I just read the top answer at this post:
http://stackoverflow.com/questions/374522/problem-inserting-string-or-null-into-sql-server-database
Correct me if I'm wrong, but can the ??-operator not only be used on two variables of the same type, if not I would greatly appreciate it, if anyone could solve my minor problem.
I tried to insert some code in my project similar to the one below.
Dictionary<string, string> strings = new Dictionary<string, string>()
{
{"@param0", strParam0},
{"@param1", strParam1},
{"@param2", strParam2}
};
foreach (string param in strings.Keys)
{
cmd.Parameters.AddWithValue(param, strings[param] ?? DBNull.Value);
}
But Visual Studio complains with the following message:
"Operator '??' cannot be applied to operands of type 'string' and 'System.DBNull'"