本文介绍了如何发送sqldatareader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
如何将sqldatareader发送到数据集或sqldataadopter?
Hello,
How to send sqldatareader to dataset?or to sqldataadopter?
string x=textBox1.Text;
string y=textBox1.Text;
DateTime fro=Convert.ToDateTime (x);
DateTime to=Convert.ToDateTime (y);
SqlConnection con = new SqlConnection(@"Data Source=.\Ahmed;Initial Catalog=Market;Integrated Security=True");
cmd = new SqlCommand("SELECT dat ,product_id FROM product where dat between '"+fro+"' and '"+to+"' ", con);
con.Open();
while (dr.Read())
{
DateTime d = (DateTime)dr["dat"];
if (d >= xx && d <= yy)
{
///////////////In here I want put the result in dataset or dataadapter
}
}
推荐答案
string x=textBox1.Text;
string y=textBox1.Text;
DateTime fro=Convert.ToDateTime (x);
DateTime to=Convert.ToDateTime (y);
SqlConnection con = new SqlConnection(@"Data Source=.\Ahmed;Initial Catalog=Market;Integrated Security=True");
string SqlQuery=string.Format("SELECT dat ,product_id FROM product where dat between '"+fro+"' and '"+to+"' ");
SqlDataAdapter adp = new SqlDataAdapter();
DataTable tab=new DataTable();
adp.Fill(tab);
con.close();
希望它可以对您有所帮助.....
Hope it may help you.....
string x=textBox1.Text;
string y=textBox1.Text;
DateTime fro=Convert.ToDateTime (x);
DateTime to=Convert.ToDateTime (y);
SqlConnection con = new SqlConnection(@"Data Source=.\Ahmed;Initial Catalog=Market;Integrated Security=True");
con.open();
string SqlQuery=string.Format("SELECT dat ,product_id FROM product where dat between '"+fro+"' and '"+to+"' ");
SqlDataAdapter adp = new SqlDataAdapter(SqlQuery,con);
DataTable tab=new DataTable();
adp.Fill(tab);
con.close();
希望对您有帮助......
Hope it may help you.....
这篇关于如何发送sqldatareader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!