zoukankan      html  css  js  c++  java
  • 调用数据库 缓存解决

    写了个页面 由于每次调用都需要连接远程的服务器,特别浪费资源,创建了aspx

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="HotProduct.ascx.cs" Inherits="resource_ascx_HotProduct" %>
    <%@ OutputCache Duration="36000" VaryByParam="none" %>

    <div class="listProduct">
    <div class="listImagetop"></div>
    <div class="imgProduct">
    <asp:Literal ID="ltrMyResult" runat="server" />
    </div>
    <div class="listImageBottom"></div>
    </div>

    cs代码

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using System.Data;
    using System.Text;


    public partial class resource_ascx_HotProduct : System.Web.UI.UserControl {
    protected void Page_Load(object sender, EventArgs e) {
    //获取图片
    using (SqlConnection con1 = new SqlConnection(@"数据连接")) {
    string strSql = string.Format("SELECT TOP 4 Id,name,Ext_ImageUrl1 FROM shop_Product WHERE (CategoryId = 36) ORDER BY CategoryId DESC");
    SqlCommand cmd = new SqlCommand(strSql, con1);
    cmd.Connection = con1;
    con1.Open();

    DataTable dtImg = new DataTable();
    SqlDataAdapter sma = new SqlDataAdapter(cmd);
    sma.Fill(dtImg);

    StringBuilder tp = new StringBuilder();

    for (int i = 0; i < dtImg.Rows.Count; i++) {
    tp.AppendFormat("<div class='imgProduct01'><a href='http://www.jiankang800.com/shop/show_{2}' target='_blank'><img src='http://www.jiankang800.com{1}' border=0 />{0}</a></div>", dtImg.Rows[i][1], dtImg.Rows[i][2], dtImg.Rows[i][0]);
    }
    ltrMyResult.Text = tp.ToString();
    }

    }
    }

    然后写在模板页的:

    <%@ Register Src="/resource/ascx/hotproduct.ascx" TagName="HotProduct" TagPrefix="anylen" %>   //注册

    <anylen:HotProduct runat="server" />// body部分

  • 相关阅读:
    MySql数据库水平扩展过程
    (转)MySQL数据库水平切分的实现原理解析
    SVN安装使用
    servlet基础
    数据库读写分离的性能分析
    java的可变长参数
    java消息服务
    static/final成员与多态
    商业软件与开源软件
    托管堆
  • 原文地址:https://www.cnblogs.com/cheshui/p/2385172.html
Copyright © 2011-2022 走看看