dealing with null value
Posted on 2012-03-29
i'm querying sql based on rowid and have an issue when a field is null.
DateReceived1 = (SQLDR.GetValue(39).ToString()).Trim() != "" ? Convert.ToDateTime(SQLDR.GetValue(39).ToString().Trim()).ToShortDateString() : "";
DateReceived1 has a datatype of datetime in the sql code and i have it as a string variable and the row i pull back has a null value so my error is:
String was not recognized as a valid DateTime. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.Convert.ToDateTime(String value)