Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Can this query allow me to search a range between from date and to date. I use from date and to date to search on
"SELECT * FROM Inventory Where DateFrom >= @dateFrom BETWEEN DateTo <= @dateTo";
Posted
Comments
Richard C Bishop 6-Feb-14 13:01pm    
You are not using the 'Between' operator correctly. Look up how to use it.

you are not a correct write query change your query according mention below.

C#
SELECT * FROM Inventory Where DateFrom between  @dateFrom and @DateTo;
 
Share this answer
 
Replace BETWEEN with AND.

or more likely:

SELECT * FROM Inventory Where [Date] >= @dateFrom and [Date] <= @dateTo
 
Share this answer
 
v2
Comments
Member 10574155 6-Feb-14 13:31pm    
How you search based on dateFrom?
Rob Philpott 6-Feb-14 13:41pm    
OK - what's the date column in the table? Is there one or two of them? What is it called?
Member 10574155 6-Feb-14 23:09pm    
Date From and Date To is two separate columns
Member 10574155 6-Feb-14 23:14pm    
Conversion failed when converting date and/or time from character string.

cmd.Parameters.AddWithValue("dateFrom", DateFrom);
SqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())
{
DateFrom= dr["DateFrom"].ToString();
DateTo= dr["DateTo"].ToString();

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