Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateTime problem

Status
Not open for further replies.

seiamerica

Technical User
Dec 27, 2005
13
US
I have a field in sql server database defined as smalldatetime. In my C# application I am selecting a date from calendar into a textbox and trying to convert the textbox value into datetime and putting back to database. I get this message all the time.
Error adding item. Please check fields.System.FormatException: String was not recognized as a valid DateTime. this is the code I am using to convert.
string test = textbox1.text;
DateTime dt = System.Convert.ToDateTime(test);
and trying to insert dt into database.
unable to get rid of this error.
Any help is appreciated.
 
I assume the exception is being raised on the Convert.ToDateTime line of code?

If so, that means that it doesn't understand the format of the value in the textbox. Switch to a masked-edit box, or better yet, a date-time picker control.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top