The parameterized query expects the parameter which was not supplied

后端 未结 6 1080
甜味超标
甜味超标 2020-11-27 05:47

I\'m having a problem with my code:

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged         


        
6条回答
  •  北海茫月
    2020-11-27 06:30

    If you pass null value to parameter,you will get this error even after you add the parameter so try to check the value and if it null then use DBNull.Value

    This will work

    cmd.Parameters.Add("@Department", SqlDbType.VarChar)
    
    If (TextBox2.Text = Nothing) Then
        cmd.Parameters("@Department").Value = DBNull.Value
    Else
        cmd.Parameters("@Department").Value = TextBox2.Text
    End If
    

    This will convert the null values from the object layer to DBNull values that are acceptable to the database.

提交回复
热议问题