Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.,
I have a field in my database that is supposed to be a datatype of datetime. but, because i can't get around that evil Conversion failed when converting date and/or time from character string while inserting datetime error. i have something like
SQL
[DateUP] NVARCHAR(25)


My search form now works using
VB
"select * from tblUsers WHERE dateUP BETWEEN '" & txtDateUp.Text & "' AND  '" & txtDateUp.Text & "23:59:59'"


My Question are:
1. What can be the Negative implications that could happen?
2. Is this a total No-No? or it depends upon how you use it for? For me its just for logging and later on search and filter by DateUp.
3. If I use nvarchar for now. (If I still have time) Can I still change it to datetime without affecting the data inside?

What I have tried:

I only use this because I could not get pass the Conversion failed when converting date and/or time from character string while inserting datetime.
I have little time to finish this project.
Posted
Updated 1-Aug-16 23:42pm

1 solution

For me it is a no go. You simply move the Problems to another section of your app, more than this, you Need to fight with this "undefined" Dates in every place you select/update the database.

Why not using a DateTimePicker which does validate the Input?

BTW: Do not use user Input directly to build your SQL Statement. Use parametrized query to avoid SQL injection.
I hope it helps.
 
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