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

前端 未结 7 1744
臣服心动
臣服心动 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 04:54

    There are two options here:

    Modify you stored procedure and make @MiddleInitial param optional (which is currently not optional that's why error is thrown)

    @MiddleInitial nvarchar(10) = NULL
    

    Or add following line to your code:

    cmd.Parameters.AddWithValue("@MiddleInitial", null);
    

提交回复
热议问题