asp.net 执行这样的代码会效率么,求大神解答,谢了
protected void bindggd()
{
using (SqlConnection conn = new SqlConnection(Conn.CONN_STRING))
{
if (Cache["xiaochi"] == null)
{
StringBuilder sb = new StringBuilder("select top 5 KeyId,CategoryId,Title from XF_News where CategoryId=18 and ShenHe=1 order by TuiJian desc,Orders desc,KeyId desc;");
sb.Append("select PicPathS,Title,TitleLinkUrl from XF_News where CategoryId=19 and ShenHe=1 order by TuiJian desc,Orders desc,KeyId desc;");
sb.Append("select * from win_sdtime;");
DataSet ds = SqlHelper.ExecuteDataset(conn, CommandType.Text, sb.ToString());
Cache.Insert("xiaochi", ds, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
rptitemgg.DataSource = ds.Tables[0];
rptitemgg.DataBind();
rprBanner.DataSource = ds.Tables[1];
rprBanner.DataBind();
dqtime.InnerText =ds.Tables[2].Rows[0]["stimeOne"].ToString();
dqtimem.InnerText =ds.Tables[2].Rows[0["stimeTwo"].ToString();
hdtime.InnerText =ds.Tables[2].Rows[0["stimeThree"].ToString();
hdtimem.InnerText=ds.Tables[2].Rows[0]["stimeFour"].ToString();
}
else
{
DataSet ds = (DataSet)Cache["xiaochi"];
rptitemgg.DataSource = ds.Tables[0];
rptitemgg.DataBind();
rprBanner.DataSource = ds.Tables[1];
rprBanner.DataBind();
dqtime.InnerText = ds.Tables[2].Rows[0]["stimeOne"].ToString();
dqtimem.InnerText = ds.Tables[2].Rows[0]["stimeTwo"].ToString();
hdtime.InnerText = ds.Tables[2].Rows[0]["stimeThree"].ToString();
hdtimem.InnerText = ds.Tables[2].Rows[0]["stimeFour"].ToString();
}
}
}
[解决办法]
懂的用Cache不错呀
不过不要把
using (SqlConnection conn = new SqlConnection(Conn.CONN_STRING))
这个放到最外面
这个应放到
if (Cache["xiaochi"] == null)
{
using (SqlConnection conn = new SqlConnection(Conn.CONN_STRING)); 放这
}
这样就不用每次必需去实例化了。
[解决办法]
现在sql还写在后台方法里?不是调用写好的? 无事务·绑定还这样蛋疼麻烦的绑定?
[解决办法]