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部分

  • 相关阅读:
    深圳移动 神州行(大众卡/轻松卡/幸福卡)套餐资费(含香港日套餐)信息及使用方法
    PHP设置时区,记录日志文件的方法
    微信公众平台消息接口使用指南
    C#日期时间格式化
    使用CMD实现批量重命名[转]
    Python高效编程技巧
    实用WordPress后台MySQL操作命令
    ubuntu-wine
    Javascript 笔记与总结(2-8)对象2
    Swift5.3 语言指南(十) 枚举
  • 原文地址:https://www.cnblogs.com/cheshui/p/2385172.html
Copyright © 2011-2022 走看看