如何发送sqldatareader [英] How to send sqldatareader

查看:53
本文介绍了如何发送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
    }
}

推荐答案

希望此代码可以为您提供帮助.如果您只想从数据库中获取一种表格格式,则可以这样使用;如果要获取多个表格,则可以使用DataSet
但是对于您的概率数据表就足够了.


Hope this code may help you . If you want to get only one Table format from Data Base means you can use like this ,If you want to fetch multiple Table means you can use DataSet
but for your prob DataTable is enough .


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.....


希望此代码可以对您有所帮助.如果您只想从数据库中获取一种表格格式,则可以这样使用;如果要获取多个表格,则可以使用DataSet
但是对于您的概率数据表就足够了.


Hope this code may help you . If you want to get only one Table format from Data Base means you can use like this ,If you want to fetch multiple Table means you can use DataSet
but for your prob DataTable is enough .


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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆