Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
please tellme any one . when i write like this textbox1.text = datetiem.now or system.datetime.utcnow. i will get error like.SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
thankq
Posted

1 solution

Difficult to be sure with that little info, but the most likely reason is that the PC is set to a locale where the date format is confusing SQL when you try to add it to the database as a string.

Instead, convert the TextBox.Text property to a DateTime value using the Parse or TryParse methods, and pass the DateTime itself to SQL as a parameter instead. You should not be passing TextBox contents to SQL directly anyway - it is a recipe for SQL Injection Attacks which can damage or destroy your database. Always use Parametrized queries to avoid this, and your Date problems will disappear as well.
 
Share this answer
 
Comments
Maciej Los 11-Oct-12 13:32pm    
Good answer, my 5!
fjdiewornncalwe 11-Oct-12 15:17pm    
+5.
damodara naidu betha 12-Oct-12 2:18am    
5+

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