Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In MS ACCESS
itmarr(0, 0) = "bill_date"
itmarr(1, 0) = TxtDate.Text

IN SQL SERVER
itmarr(0, 0) = "bill_date"
itmarr(1, 0) = Format(TxtDate.Text, "dd MMM yyyy")

ERROR SHOW IN SQL SERVER]
the conversion of a varchar data type to a datetime data type resulted in an out-of-range value

What I have tried:

Insert/update datetime from VB6 to Sql Server
Posted
Updated 10-Mar-17 2:24am
Comments
Richard MacCutchan 27-Feb-17 3:33am    
The error message is clearly telling you what is wrong. Check the values of your variables to see why.
Jitendra shekhawat 27-Feb-17 4:03am    
Please tell me error....??
and how to solution this problem.....
please help...
Richard MacCutchan 27-Feb-17 6:23am    
The error is as detailed in the message. And the solution is to check your code and your data to see why it is not valid. Remember, we cannot see your screen so have no idea what information your system is trying to process.
Jitendra shekhawat 27-Feb-17 6:32am    
ohk, sir
thanx

1 solution

Always try to use "unambiguous dates" when passing information around - especially to and from databases.

What does that actually mean? It means use a date format that cannot be misinterpreted no matter which in country or time zone you're in nor which language is being used.

Example: 01/06/2016 would be 1st June in the UK but 6th January in the USA.

You are pretty close because you have used dd MMM yyyy as the format. Which is fine in most languages ... "27 Feb 2017" works in English, Dutch, German, etc etc but in Finnish would be meaningless (Finnish for February is helmikuu). It's not unusual these days to have SQL Server servers hosted in different countries to the one where the application is running. Nor is it unusual to have users from multiple countries accessing the same SQL database.

There are two formats for dates that are guaranteed to work for all versions of SQL Server. Usefully they work for most other databases as well.
yy-MM-ddTHH24:mi:ss
and
yyyyMMdd HH24:mi:ss
It's also worth having a read up on the ISO standard for dates - ISO 8601 - Wikipedia[^]

If this doesn't solve your specific problem, then put a breakpoint (F9) on the line
VB
itmarr(1, 0) = Format(TxtDate.Text, "dd MMM yyyy")
and have a look at the contents of TxtDate - you'll probably find that it can't be formatted as a date at all. You should really add some validation OR use a DatePicker control.
 
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