Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table1

in which there is a column name 'date' which datatype is datetime

nd now i want select between two dates which is the value from datetimepicker
how i do it.
Posted

SQL
SELECT datefield
FROM table
WHERE datefield BETWEEN @date1 AND @date2
 
Share this answer
 
Comments
Maciej Los 22-Nov-13 8:44am    
5ed!
Abhijeet pratap singh 22-Nov-13 8:59am    
not getting it
datetimepicker return value in dd/mm/yyyy hh:mm:ss pm
and it will not sorting
i used @datetimepicker1.value instead of @date1
ZurdoDev 22-Nov-13 9:03am    
You'll need to post a lost more code then and be clear on what the issue is.
Abhijeet pratap singh 22-Nov-13 9:07am    
selectQueryString = "SELECT * FROM misc_info WHERE misc_date BETWEEN @'" + dateTimePicker1.Value + "' AND @'"+dateTimePicker2.Value+"'";
con.Open();
try
{
sqlDataAdapter = new SqlDataAdapter(selectQueryString, con);
sqlCommandBuilder = new SqlCommandBuilder(sqlDataAdapter);
dataTable = new DataTable();
sqlDataAdapter.Fill(dataTable);
bindingSource = new BindingSource();
bindingSource.DataSource = dataTable;
dataGridView1.DataSource = bindingSource;

}
catch (Exception rr)
{ }
Abhijeet pratap singh 22-Nov-13 9:08am    
in this grid i have all rows
now i want sorted according to date
between two datetimepicker
Solution1 by RyanDev is very good and i would add some extra information.

You can use stored procedure with body as is shown above. Please, read this: How to: Execute a Stored Procedure that Returns Rows[^]
 
Share this answer
 
Comments
Abhijeet pratap singh 22-Nov-13 9:05am    
selectQueryString = "SELECT * FROM misc_info WHERE misc_date BETWEEN @'" + dateTimePicker1.Value + "' AND @'"+dateTimePicker2.Value+"'";
con.Open();
try
{
sqlDataAdapter = new SqlDataAdapter(selectQueryString, con);
sqlCommandBuilder = new SqlCommandBuilder(sqlDataAdapter);
dataTable = new DataTable();
sqlDataAdapter.Fill(dataTable);
bindingSource = new BindingSource();
bindingSource.DataSource = dataTable;
dataGridView1.DataSource = bindingSource;

}
catch (Exception rr)
{ }
Abhijeet pratap singh 22-Nov-13 9:06am    
in this grid i have all rows
now i want sorted according to date
between two datetimepicker
Jawad Ahmed Tanoli 22-Nov-13 11:08am    
use order by misc_date in your query

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