The parameterized query which was not supplied

前端 未结 3 1503
野趣味
野趣味 2021-01-04 19:28

I keep getting this error :

The parameterized query \'(@AdminEmail nvarchar(4000),@AdminPassword nvarchar(4000))SELECT\' expects the parameter \'@A

3条回答
  •  滥情空心
    2021-01-04 20:06

    Your @AdminEmail variable EMail is null. You cannot pass a null on a required parameter. Use DBNull.Value.

    When using null, you are informing Sql Server that you are omitting the parameter. This can be useful for an optional parameter with a default value, but causes an error for a required parameter.

    I recommend that you use always use a utility function when passing a value to a command parameter.

    For example:

    public static object GetDataValue(object value)
    {
       if(value == null)
       {
           return DBNull.Value;
       }
    
       return value;
    }
    

    and then use

    cmd.Parameters.AddWithValue("@AdminEmail", GetDataValue(EMail))
    

提交回复
热议问题