Reputation: 2850
I'm trying to check for DBNull.Value
but in this case reader["Preferences"]
returns {} in the immediate window (why?)
so when (string)reader["Preferences"];
executes I get a type casting error
if (reader["Preferences"] == System.DBNull.Value)
{
preferences = (string)reader["Preferences"];
}
Upvotes: 0
Views: 908
Reputation: 499002
You are trying to cast only when the value is DBNull.Value
.
You should invert your if
:
if (reader["Preferences"] != System.DBNull.Value)
{
preferences = (string)reader["Preferences"];
}
Upvotes: 1