Click here to Skip to main content
15,912,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have to search data -> date_from TO date_to.
Ex:
I have to show list of data where
enquery made from date:1/1/2012 to 10/1/2012
this date value are in textbox.

I have use this query,but can't working:
select *from call_details where enquiry_date='" + txt_datefrom.Text + "' to '" + txt_dateto.Text + "'"
Posted

Use Query like:
 "Select * from call_details where enquiry_date between '" + txtStartDate.txt + "' and '" + txtEndDate.text + "'";
 
Share this answer
 
Use this query

SQL
select * from table_name where date_column_name between from_date and To_date
 
Share this answer
 
try this

C#
"select * from call_Details 
where enquirydate between '"+DateTime.Parse( txt_datefrom.Text) + "' and '"
+DateTime.Parse( txt_dateto.Text) +"'";


But this will lead to sql injection.so use sql parameters always

it should be
C#
SqlCommand command = new SqlCommand("select * from call_Details
where enquirydate between @startdate and @enddate", connection))  ;    
command.Parameters.Add(new SqlParameter("@startdate" , DateTime.Parse(text_datefrom.Text)));
command.Parameters.Add(new SqlParameter("@enddate" , DateTime.Parse(text_dateto.Text)));
 
Share this answer
 
v4

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