SQL Query says a parameter is not supplied, but is added to the SqlCommand object

后端 未结 4 646
南旧
南旧 2020-12-17 09:24

I have a stored procedure that has a parameter called UserName and in my code behind I have a SqlCommand object that I add the parameters to with the Add method. But for som

4条回答
  •  执笔经年
    2020-12-17 09:45

    You will get this exception if the value of your 'userName' variable is null

    If null is valid, then pass 'DBNull.Value' to the db instead:

    command1.Parameters.Add(new SqlParameter("@UserName", (userName ?? DBNull.Value));   
    

提交回复
热议问题