Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: SQL-Server
hi all,
please tellme any one . when i write like this textbox1.text = 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.
Posted 11-Oct-12 5:17am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

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

  Print Answers RSS
0 DamithSL 400
1 Maciej Los 222
2 OriginalGriff 213
3 Zoltán Zörgő 135
4 BillWoodruff 130
0 OriginalGriff 7,969
1 DamithSL 6,139
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,309
4 Kornfeld Eliyahu Peter 4,539

Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100