C# ASP.Net Parameters.AddWithValue rejecting null value for parameter

前端 未结 7 1742
臣服心动
臣服心动 2021-01-18 04:22

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:

相关标签:
7条回答
  • 2021-01-18 05:02

    You can add to project and use following extension method:

    public static SqlParameter AddWithValueSafe(this SqlParameterCollection parameters, string parameterName, object value)
    {
        return parameters.AddWithValue(parameterName, value ?? DBNull.Value);
    }
    
    0 讨论(0)
提交回复
热议问题