SqlDataReader和SqlDataAdapter嵌套
DataSetds=newDataSet();stringstri="selectTimefromShop";SqlCommandcmd=newSqlCommand(st...
DataSet ds = new DataSet();
string stri = "select Time from Shop";
SqlCommand cmd = new SqlCommand(stri, con);
//SqlDataAdapter a = new SqlDataAdapter();
// a.SelectCommand = cmd;
//DataSet MyDataSet = new DataSet();
SqlDataReader dr = cmd.ExecuteReader();
dr.Close();
while (dr.Read())
{
string sum = dr[0].ToString();
DateTime dt1 = Convert.ToDateTime(sum);
DateTime dt2 = DateTime.Now;
if (dt1.Month == dt2.Month)
{
TimeSpan midTime = dt2 - dt1;
int ab = midTime.Days;
if (ab <= 0)
{
//Response.Write(ab);
//dr.Close();
string b = "select * from Shop where Time='" + dt1 + "' ";
SqlDataAdapter da = new SqlDataAdapter(b, con);
da.Fill(ds);
GridView3.DataSource = ds;
GridView3.DataBind();
con.Close();
}
else
{
con.Close();
return;
}
}
}
con.Close();
return; 展开
string stri = "select Time from Shop";
SqlCommand cmd = new SqlCommand(stri, con);
//SqlDataAdapter a = new SqlDataAdapter();
// a.SelectCommand = cmd;
//DataSet MyDataSet = new DataSet();
SqlDataReader dr = cmd.ExecuteReader();
dr.Close();
while (dr.Read())
{
string sum = dr[0].ToString();
DateTime dt1 = Convert.ToDateTime(sum);
DateTime dt2 = DateTime.Now;
if (dt1.Month == dt2.Month)
{
TimeSpan midTime = dt2 - dt1;
int ab = midTime.Days;
if (ab <= 0)
{
//Response.Write(ab);
//dr.Close();
string b = "select * from Shop where Time='" + dt1 + "' ";
SqlDataAdapter da = new SqlDataAdapter(b, con);
da.Fill(ds);
GridView3.DataSource = ds;
GridView3.DataBind();
con.Close();
}
else
{
con.Close();
return;
}
}
}
con.Close();
return; 展开
3个回答
展开全部
DataSet ds=new DataSet();
sqlConnection conn=new sqlConnection(ConfigurationSettings.AppSettings[ "xxx"]);
sqlConnection conn1=new sqlConnection(ConfigurationSettings.AppSettings[ "xxx"]);
conn.open();
sqlcommand cmd=new sqlcommand("select Time from Shop",conn);
sqlDatareader dr=cmd.ExecuteReader();
while(dr.Read())
{
string sum = dr[0].ToString();
DateTime dt1 = Convert.ToDateTime(sum);
DateTime dt2 = DateTime.Now;
if (dt1.Month == dt2.Month)
{
SqlDataAdapter da=new SqlDataAdapter( "select * from Shop where Time='" + dt1 + "' ",conn1);
da.fill(ds,"xx");
GridView3.DataSource=ds.Tables[ "xx"].DefaultView;
GridView3.DataBind();
}
}
sqlConnection conn=new sqlConnection(ConfigurationSettings.AppSettings[ "xxx"]);
sqlConnection conn1=new sqlConnection(ConfigurationSettings.AppSettings[ "xxx"]);
conn.open();
sqlcommand cmd=new sqlcommand("select Time from Shop",conn);
sqlDatareader dr=cmd.ExecuteReader();
while(dr.Read())
{
string sum = dr[0].ToString();
DateTime dt1 = Convert.ToDateTime(sum);
DateTime dt2 = DateTime.Now;
if (dt1.Month == dt2.Month)
{
SqlDataAdapter da=new SqlDataAdapter( "select * from Shop where Time='" + dt1 + "' ",conn1);
da.fill(ds,"xx");
GridView3.DataSource=ds.Tables[ "xx"].DefaultView;
GridView3.DataBind();
}
}
展开全部
SqlDataReader和SqlDataAdapter嵌套应该不能运行的!SqlDataReader是一条一条地读到内存的
追问
我的意思是从订单中读取时间与当前时间进行比较,如果是当天就显示在GridView3,请问您有什么好方法吗 我是初学者望帮忙 有代码更好 谢谢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼主。。。。你就直接做两个查询啊,一个是查询今天的订单显示到GV3,另外不是今天的放到另外一个GV里面就可以了啊。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询