hiii..
i want to get multiple rows from database...
SqlCommand cmd = new SqlCommand("SELECT * FROM dateshort WHERE from_date BETWEEN '" + from + "' AND '" + to + "' ", mycon);
using this query i want to fetch the in between dates ...
but i don't konw how to implement in c#...
Ahmed JSPosted Nov 23, 2014, 10:21 AM
use this code
DateTime from =Convert.ToDateTime(from);
DateTime to =Convert.ToDateTime(to);
SqlCommand cmd = new SqlCommand("SELECT * FROM dateshort WHERE from_date BETWEEN '" + from.ToString("dd/MMM/yyyy") + "' AND '" + to.ToString("dd/MMM/yyyy") + "' ", mycon);
Please Mark This answer if it is helpful to you.
Vikram AgrawalPosted Nov 23, 2014, 1:45 AM
If at all you want to to retrieve data from database into your application you can do it as following:
SqlConnection con=new SqlConnection("CONNECTIONSTRING");
SqlCommand cmd=new SqlCommand("Select * From myTable Where DateColumn Between '" + fromDate + "' AND '" + toDate + "'",con);
con.Open();
SqlDataReader reader=cmd.ExecuteReader();
Now u will get all filtered record in reader object and you can use this as per your need.
Thanks.
Please Mark This answer if it is helpful to you.
Ranjit PowarPosted Nov 23, 2014, 1:33 AM
SqlDataAdapter da=new SqlDataAdapter("SELECT * FROM dateshort WHERE from_date BETWEEN '" + from + "' AND '" + to + "' ", mycon);
DataTable dt=new DataTable();
da.Fill(dt);
Now you can get all selected rows in data table.