Unable to cast object of type 'System.DBNull' to type 'System.String'
I know this is really simple stuff but as a beginner it took me a while to figure this out. If you use the Convert.ToString method then even though your data may be the correct datatype to start with it will convert a null value to an empty string instead of throwing the above error.
MyStringVariable = Convert.ToString(myDataReader["MyDBFieldName"]);
No comments:
Post a Comment