Wednesday, March 7, 2012

Problems with DateTime

Hello all,
I have a problem when I try to insert with a SQL Command a value obtained from a Calendar Control in a SQL Server table. I get the date from the calendar and I put it in a TextBox, but when I try to insert this value in a DateTime defined field I have the following error:
The string or binary data would be truncated. The instruction was finished.

Could you help me?

Thanks.You need to convert the text into a c#/vb date type first. You're prob' hitting a localization issue with the date format.|||I'm certainly no SQL server pro but from my limited experience, SQL server is persnickety about datetime values. I avoid the problem altogether by passing the date in your SQL statement as a string (wrapping it w/in single quotes) or, if you are using sprocs, converting it to datetime w/in the sproc in SQL Server.

good luck.|||No don't wrap it as a string that's exactly where you start getting the problems. If you wrap it as a string you need to either know the database format (and be able to convert to it) or you have to convert to a universal format. Much better to use a param.

No comments:

Post a Comment