Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.NET:使用变量生成MySQL查询_Mysql_.net_Vb.net_Variables - Fatal编程技术网

VB.NET:使用变量生成MySQL查询

VB.NET:使用变量生成MySQL查询,mysql,.net,vb.net,variables,Mysql,.net,Vb.net,Variables,我已经编写了下面的代码来更新我的表,但它不起作用 sqlstr = "UPDATE Student SET " & S & " = @field1, " & L & " = @field2, " & R & " =@field3, " & W & "=@field4 WHERE Code='" & StdID & "'" DBCmd = New MySql.Data.MySqlClient.MySqlCommand(

我已经编写了下面的代码来更新我的表,但它不起作用

sqlstr = "UPDATE Student SET " & S & " = @field1, " & L & " = @field2, " & R & " =@field3, " & W & "=@field4 WHERE Code='" & StdID & "'"
DBCmd = New MySql.Data.MySqlClient.MySqlCommand(sqlstr, DBConn)
With DBCmd
        .Parameters.AddWithValue("@field1", CB_S.SelectedItem)
        .Parameters.AddWithValue("@field2", CB_L.SelectedItem)
        .Parameters.AddWithValue("@field3", CB_R.SelectedItem)
        .Parameters.AddWithValue("@field4", CB_W.SelectedItem)
    End With
    DBCmd.Dispose()
其中S、L、R和W是字符串:S1、L1、R1、W1。 StdID是一个整数。CB_S、CB_L、CB_R和CB_W是组合框


谁能告诉我出了什么问题吗?

您没有打开
连接
并调用
ExecuteNonQUery()
。还参数化了
code

sqlstr = "UPDATE Student SET " & S & " = @field1, " & L & " = @field2, " & R & " =@field3, " & W & "=@field4 WHERE Code=@code"
DBCmd = New MySql.Data.MySqlClient.MySqlCommand(sqlstr, DBConn)
With DBCmd
        .Parameters.AddWithValue("@field1", CB_S.SelectedItem)
        .Parameters.AddWithValue("@field2", CB_L.SelectedItem)
        .Parameters.AddWithValue("@field3", CB_R.SelectedItem)
        .Parameters.AddWithValue("@field4", CB_W.SelectedItem)
        .Parameters.AddWithValue("@code", StdID)
End With
DBConn.Open()
DBCmd.ExecuteNonQuery()

哦,太尴尬了!!谢谢