Click here to Skip to main content
Sign Up to vote bad
good
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:12


3 solutions

 Use Query like:
  "Select * from call_details where enquiry_date between '" + txtStartDate.txt + "' and '" + txtEndDate.text + "'"; 
  Permalink  
Use this query
 
select * from table_name where date_column_name between from_date and To_date
  Permalink  
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  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 508
1 Arun Vasu 275
2 Maciej Los 238
3 OriginalGriff 215
4 Mahesh Bailwal 200
0 Sergey Alexandrovich Kryukov 9,670
1 OriginalGriff 7,409
2 CPallini 3,968
3 Rohan Leuva 3,352
4 Maciej Los 2,861


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid