I am trying to call a MySQL stored procedure from .NET that accepts a NULL value in one of the parameters. I build my parameter list from below and I keep getting an error when I set DBNull.Value by looking at the value in Visual Studio shows {}. I am not sure why this is erroring, but doesn’t give any detailed message of why.
protected IEnumerable<MySqlParameter> BuildParameterList(IEnumerable<KeyValuePair<string, object>> parameters)
{
return parameters.Select(parameter => new MySqlParameter(parameter.Key, parameter.Value ?? DBNull.Value)
{
IsNullable = parameter.Value == null
});
}
Fixed it by doing this. Looks like MySQL didn’t like AnsiString which was the default datatype for null.