I have a table that has a few columns that sometimes will have a null value. How can I check if a value is null, and if so set the value to an empty string or something that I can use later?
private DateTime dtDate_Ordered;
private DateTime dtDate_Required;
private DateTime dtDate_Received;
var stringSql = "select * from po where po_num=" + stringPO_NUM;
var Class_Connection = new SQL_Connection();
Class_Connection.cnn.Close();
Class_Connection.cnn.Open();
try
{
var cmd = new SqlCommand(stringSql, Class_Connection.cnn);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
dtDate_Ordered = (DateTime)sdr["dateordered"];
dtDate_Required = (DateTime)sdr["daterequired"];
dtDate_Received = (DateTime)sdr["daterecv"];
stringComments = (string)sdr["comments"];
}
}
catch (Exception Ex)
{
Class_Connection.cnn.Close();
throw Ex;
}
Class_Connection.cnn.Close();
RDI_Date_Ordered.SelectedDate = dtDate_Ordered;
RDI_Date_Required.SelectedDate = dtDate_Required;
RDI_Date_Received.SelectedDate = dtDate_Received;
I would like to be able to handle the null value, before the exception handler catches it.
stringComments = (sdr["comments"] = DbNull.Value ? string.Empty : dr.GetString(dr.GetOrdinal("comments")));DBNull.Value==to do the inline comparison