Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 7-Jan-13 19:12pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

 Use Query like:
  "Select * from call_details where enquiry_date between '" + txtStartDate.txt + "' and '" + txtEndDate.text + "'"; 
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use this query
 
select * from table_name where date_column_name between from_date and To_date
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

try this
 
"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
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)));
  Permalink  
v4

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 271
1 OriginalGriff 253
2 nv3 50
3 VJ Reddy 45
4 Mehdi Gholam 45
0 Sergey Alexandrovich Kryukov 6,696
1 OriginalGriff 6,149
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100