I am populating tables using a stored procedure. The table allows a \'null\' for the middle initial of the name, but I\'m getting the following error message:
I created an extension method to battle this problem. Marcin's suggestion is also worth considering if you can update the stored procedure.
cmd.Parameters.AddString("@MyParamName", myValue);
public static class SQLExtension
{
public static void AddString(this SqlParameterCollection collection, string parameterName, string value)
{
collection.AddWithValue(parameterName, ((object)value) ?? DBNull.Value);
}
}