I have a table with a DateTime column the column can have NULL values
Now I connect to the database using an ODBC connection and get the value into a DataTable in .net / c#.
I am able to check it for NULL by going
if(String.IsNullOrEmpty(table.rows[0][0].ToString()) {      //Whatever I want to do }   Is String.IsNullOrEmpty the correct way to check for null values.
foreach(DataRow row in dataTable. Rows) { if(row. IsNull("myColumn")) throw new Exception("Empty value!") }
IsNullOrEmpty() Method of C# If any string is not assigned any value, then it will have Null value. The symbol of assigning Null value is “ “or String. Empty(A constant for empty strings). This method will take a parameter that will be of System.
Use DBNull.Value.Equals on the object without converting it to a string.
Here's an example:
   if (! DBNull.Value.Equals(row[fieldName]))     {       //not null    }    else    {       //null    } 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With