Click here to Skip to main content
Sign Up to vote bad
good
See more: SQL-Server
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 11 Oct '12 - 4:17


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.
  Permalink  
Comments
Maciej Los - 11 Oct '12 - 13:32
Good answer, my 5!
Marcus Kramer - 11 Oct '12 - 15:17
+5.
damodara naidu betha - 12 Oct '12 - 2:18
5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,123
1 OriginalGriff 6,040
2 CPallini 3,432
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid