SqlCommand cmd = new SqlCommand("SELECT * FROM [order] WHERE date>=@begin AND date<=@end", con);
 cmd.Parameters.AddWithValue("@begin",dt1);
 cmd.Parameters.AddWithValue("@end", dt2);
This is my select statement. I want to put the result to data gridview. How to use dataset to store in gridview in asp.net C#?
Use a SqlDataAdapter.
SqlCommand cmd = new SqlCommand("SELECT * FROM [order] WHERE date>=@begin AND date<=@end", con);
cmd.Parameters.AddWithValue("@begin",dt1);
cmd.Parameters.AddWithValue("@end", dt2);
SqlDataAdapter sda = new SqlDataAdapater(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
yourGridView.DataSource = dt;
yourGridView.DataBind();
                        You need a SqlDataReader object to execute your command and a DataTable to load the results into the GridView:
   SqlDataReader dr = cmd.ExecuteReader();
   DataTable dt = new DataTable();
   dt.Load(dr);
   gv.DataSource = dt;
   gv.DataBind();
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With