Click here to Skip to main content
15,886,723 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using ms-access as database backend, and visual studio 08 for frontend in windows application.

For a cashbook table, I have Date column whose data type is string so that I can store data in my custom format like '12 -Jan -2011' .

This value is coming from dateTimePicker.Text property.
I have used custom property of dateTimePicker.

It is working fine for insert, update and delete, but when I am running query to find data 'date between', it is not giving proper result.

what can be best option to resolve this problem with least modification ?
:confused::confused:

Regards,
*REMOVED MAIL*
Posted
Updated 12-Jan-11 21:39pm
v3
Comments
JF2015 13-Jan-11 2:43am    
Edited to remove mail address. Never post your mail address in a public forum to avoid being spammed. You will get an automated mail if someone answers your question
Dalek Dave 13-Jan-11 3:39am    
Edited for Grammar, Spelling and Syntax.

Date column has type is string (varchar, nvarchar, ...). So, when you select this column with between clause, SQL cannot select exactly the result which you want.

Notice that, between clause only apply to some datatype, such as DateTime, SmallDateTime, int,... (datetime and Number only).

Please cast Date column into datetime before querying
SELECT Date FROM CashBook WHERE cast(Date as datetime) BETWEEN '...a from date here' AND '...a to date here'


Andy
 
Share this answer
 
v2
Comments
arshad alam 17-Jan-11 0:27am    
it is not working in ms-access . have you cheched it out??
jerrykid 19-Jan-11 23:51pm    
Sorry, I forgot you mentioned in Access :). In Access you can use CONVERT function to convert Date column
Your problem is specifically that you are using a string.
It will search between the values of the strings, not between dates.

You will need to convert the Date as a string to a Date as a Date.

Or, much easier, use one of the Date options to format the date properly, giving it's format in a Day Month Year style.

That would obviate the problem altogether.
 
Share this answer
 

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