Click here to Skip to main content
15,901,853 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
How to send sqldatareader to dataset?or to sqldataadopter?

C#
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
    }
}
Posted
Updated 6-Nov-12 5:41am
v2
Comments
RaisKazi 6-Nov-12 10:46am    
why u want to do that?
Member 8584763 6-Nov-12 10:53am    
if it's possible it'll make you code easier.
jim lahey 6-Nov-12 10:47am    
not clear.
Member 8584763 6-Nov-12 10:53am    
if it's possible it'll make you code easier.
jim lahey 6-Nov-12 10:59am    
that's even less clear.

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 .


C#
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.....
 
Share this answer
 
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 .


C#
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.....
 
Share this answer
 
Comments
Member 8584763 6-Nov-12 12:52pm    
still in this line
adp.Fill(tab);
it gives me
Conversion failed when converting date and/or time from character string.
arunrv 9-Nov-12 11:53am    
What is the DataType of column "dat" in your DataBase Table..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900