The parameterized query which was not supplied

前端 未结 3 1479
野趣味
野趣味 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:02

    Is it possible that the EMail property is null (Email is Nothing)? I think you might get that error in that case. Be sure that EMail = String.Empty or EMail = "" before you set your parameter value.

    Edit: Or as another answer suggests, you can send DBNull.Value instead if you actually want nulls in your database.

    0 讨论(0)
  • 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))
    
    0 讨论(0)
  • 2021-01-04 20:07

    Step through your code and see what the value of Email and Password are. Chances are they are null.

    0 讨论(0)
提交回复
热议问题