You can legally store a null in a column from a data row and the code will compile. Don’t do this thought because it will definitely throw an exception during run time 🙂

dr[“columnName”] = null; //This will throw an exception during run time

The remedy is to just use DBNull.Value:

dr[“columnName”] = DBNull.Value; //This is legal

Leave a Reply

Your email address will not be published. Required fields are marked *