Click here to Skip to main content
11,711,220 members (84,373 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#3.0 C#4.0 WinForm
Hi Guys,
I am facing the problem regarding
"String was not recognized as a valid DateTime".and type of exception "Format Exception was caught" excpetion throws when i am trying to click cellcontent Click event of gridview column

the code -
objCardDet.SubscribeDate = DateTime.Parse(dtGvCardDetails.Rows[e.RowIndex].Cells[4].Value.ToString());

please help me..
Thanx in advance
Posted 9-Apr-13 18:41pm
indrajeet jadhav at 10-Apr-13 0:50am
and I already try objCardDet.SubscribeDate=convert.TodateTime(dtGvCardDetails.Rows[e.RowIndex].Cells[4].Value.ToString());
Sergey Alexandrovich Kryukov at 10-Apr-13 0:56am
Don't try anything. Use the debugger and figure out what's going on.
indrajeet jadhav at 10-Apr-13 1:03am
objCardDet.SubscribeDate = {01-01-0001 AM 12:00:00} this is it..showing in after that code line.n look at the date..

1 solution

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

Solution 1

This is because you are parsing the string without specifying exact format of the string representing time, which is not the same which is expected by default. Please specify the format exactly using one of the System.String.DateTime.ParseExact or System.String.DateTime.TryParseExact:[^].

Remember that ParseExact throws exception is the recognition is failed, so you should either handle the exception, or use the TryParseExact form.

For format specifiers, please see:[^],[^].


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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 549
1 OriginalGriff 255
2 Peter Leow 154
3 Maciej Los 120
4 Abhinav S 120
0 Maciej Los 95
1 Richard MacCutchan 90
2 Abhinav S 90
3 OriginalGriff 80
4 Member 4653839 50

Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 10 Apr 2013
Copyright © CodeProject, 1999-2015
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