Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
rs.Open "select PDATE,plan,NAME,PQNTY  from purch where pdate>=" & DTPicker1.Value & " and pdate<=" & DTPicker2.Value & " order  by name,pdate", cn, adOpenKeyset, adLockOptimistic


now rs=0, but
VB
rs.Open "select PDATE,plan,NAME,PQNTY from purch  order by name,pdate ", cn, adOpenKeyset, adLockOptimistic

rs.Filter = "pdate>=" & DTPicker1.Value & " and pdate<=" & DTPicker2.Value


rs # 0 Why ? Please give answers are code
Posted
Comments
Maciej Los 8-Jul-13 5:32am    
Which database: MS Access, MS SQL Server?

To get proper values from MS Acces database, you need take dates between #
VB
"SELECT PDATE, plan, [NAME], PQNTY  from purch" & vbcr & _
"WHERE pdate>=#" & DTPicker1.Value & "# and pdate <= #" & DTPicker2.Value & "#"  & vbcr & _
"ORDER BY [name], pdate"

BTW: Name is reserved word in MS Access, so... to use it you need to take it in a brackets []

To get proper values from MS SQL Server, you need take dates between '
VB
"SELECT PDATE, plan, [NAME], PQNTY  from purch" & vbcr & _
"WHERE pdate>='" & DTPicker1.Value & "' and pdate <= '" & DTPicker2.Value & "'"  & vbcr & _
"ORDER BY [name], pdate"


I would suggest you to use BETWEEN ... AND ...[^] statement.
More about filtering data in MS Access database: Examples of query criteria[^]

I almost forgot...
In MS Access database queries dates must be formated as MM/dd/yyyy (US format).
 
Share this answer
 
v2
try this..:)

SQL
SELECT * FROM TableName 
WHERE  (date_field BETWEEN '2010-01-30 14:15:55' AND '2010-09-29 10:15:55') ORDER BY colimn1 ASC,column2 DESC
 
Share this answer
 
v2

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