所以我有一个按钮,它应该根据文本框中的输入从sql搜索数据库,如果成功则选择整行,然后删除该行。
到目前为止,这是我的代码,
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myConnection = New SqlConnection("Data source=.; initial catalog = saleCo; integrated security=true")
myConnection.Open()
Dim deleteProduct = New SqlCommand()
Dim deleteProductcmd As String = "DELETE FROM PRODUCT WHERE P_CODE = @p_code"
deleteProduct.Connection = myConnection
deleteProduct.CommandText = deleteProductcmd
deleteProduct.Parameters.Remove("@p_code", TextBox2.Text)
deleteProduct.ExecuteNonQuery()
myConnection.Close()
代码似乎遇到了“deleteProduct.Parameters.Remove”行的问题 主要是“。删除”部分。有什么方法可以改变它以某种方式工作?
答案 0 :(得分:2)
应该是
deleteProduct.Parameters.AddWithValue("@p_code", TextBox2.Text)