Click here to Skip to main content
15,896,417 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all I import the excel 1 sheet in data grid view. In the excel file having Records in date and time format, if any cell of record is null how to save the record, while I am save the record it’s showing the Error “String was not recognized as a valid Date Time”
Posted
Comments
Zoltán Zörgő 5-Feb-13 3:35am    
You can use nullable variable - but it depends on your code. Please improve your question by adding the code row(s) you use to read the datetime value from the cell.
lukeer 5-Feb-13 4:34am    
Don't repost the same question[^] again. Use the original question's "Improve question" link instead to provide further insight. That way, you will have all answers in one thread. And potential helpers don't have to waste their time on answers you already got.

Initialize Your DateTime property like below
C#
public DateTime? Date{get;set;}


Hope this helps
 
Share this answer
 
Comments
Ankur\m/ 5-Feb-13 3:52am    
Should have also mentioned that it is called nullable type. Anyways 5!
Abhinav S 5-Feb-13 4:22am    
Yes that is correct.
The easiest option would be to use a nullable type[^].
E.g. DateTime? dt = null;

Here[^] is a good example.

However, you will need to make sure you check this value for null before display.
 
Share this answer
 
Comments
Ankur\m/ 5-Feb-13 3:52am    
Correct!
Abhinav S 5-Feb-13 4:19am    
Thanks.
C# does support Nullable DateTime[^]
C#
DateTime? MyNullableDate = null;

is a valid statement.
 
Share this answer
 
Comments
Ankur\m/ 5-Feb-13 3:51am    
Couple of answers came in while I was typing mine. :0
Abhinav S 5-Feb-13 4:19am    
5. Of course.
See Use Nullable Types![^]

Cheers,
Edo
 
Share this answer
 

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