I\'m trying to add a column to an existing DataRow in C#. Afterwards the column will be filled with a single value from my database.
DataRow dr already
Clearly in production you have either a NULL returned from the command execution or something different in the connectionstring or whatever; as a general rule you should always test for DBNull before casting/converting directly to another type the result of ExecuteScalar.
Check Rein's answer here (and vote him up) for his nice suggested solution:
Unable to cast object of type 'System.DBNull' to type 'System.String`