SqlCommand cmdm = new SqlCommand("select *from dbv_mcpagg where recorddate='" + Date.ToString("yyyy-MM-dd") + "'", conn);
SqlDataReader strm = cmdm.ExecuteReader();
while (strm.Read())
{
this.bmc_prod.Text = strm["production"].ToString();
this.bmc_tot.Text = strm["totalqty"].ToString();
}
strm.Close();
//------------------------------------------------------------------------------------------------------------
SqlCommand cmddt = new SqlCommand("select *from dbv_dtagg where recorddate='" + Date.ToString("yyyy-MM-dd") + "'", conn);
SqlDataReader strdt = cmddt.ExecuteReader();
while (strdt.Read())
{
this.bmc_dt.Text = strdt["Downtime"].ToString();
}
strdt.Close();
假如一个页面中有几十个要查询的,而且每个要查询的数据都不在同一个数据库,那不是要重复写很多了啊,有没有什么简便的方法?
SqlDataReader strm = cmdm.ExecuteReader();
while (strm.Read())
{
this.bmc_prod.Text = strm["production"].ToString();
this.bmc_tot.Text = strm["totalqty"].ToString();
}
strm.Close();
//------------------------------------------------------------------------------------------------------------
SqlCommand cmddt = new SqlCommand("select *from dbv_dtagg where recorddate='" + Date.ToString("yyyy-MM-dd") + "'", conn);
SqlDataReader strdt = cmddt.ExecuteReader();
while (strdt.Read())
{
this.bmc_dt.Text = strdt["Downtime"].ToString();
}
strdt.Close();
假如一个页面中有几十个要查询的,而且每个要查询的数据都不在同一个数据库,那不是要重复写很多了啊,有没有什么简便的方法?
解决方案 »
- 网页快照保存的是哪些内容呀?除了文本,包括图片等信息吗?
- CMS系统的“评论”模块数据表问题
- 帮我看看,偶不会啦....
- 请问: <body MS_POSITIONING="GridLayout">是什么意思啊??
- 简单问题:将客户端文本文件内容读出,出入数据库text字段,读出内容为String 类型。在线等,即时给分
- 请教:
- 如何引用XML中的一段字符串
- 谁有《构建Web解决方案-应用asp.net和ado.net》这本书的随书源码,谢谢!!!
- 如何识别从串口中读到的中文信息?
- 如何动态设置CheckBoxList里面各个checkbox的状态?有关Attributes
- 大侠请帮忙!!!
- asp.net数据库的连接问题
傳SQL進去
返回一個DataReader
此方法传两个参数(库名,sql语句) 返回一个 SqlDataReader
然后在这个方法里实现连接数据库和执行SqlCommand,并且返回一个 SqlDataReader
StringBuilder sb = new StringBuilder();
sb.AppendFormat("select * from {0} ",数据库参数);
sb.Append(" where ......")string sql = sb.ToString();
SqlCommand cmddt = new SqlCommand(sql,conn);