我正在尝试使用 case 条件和一些附加条件创建一个查询,以避免循环。我不知道问题出在哪里。
代码在这里:
Using MysqlConn As New MySqlConnection(connString)
Using MyCommand As New MySqlCommand()
With MyCommand
.Connection = MysqlConn
.CommandText = "update beardata.results set team = case rownumber" & _
"when 1 then @par1" & _
"when 2 then @par1" & _
"when 3 then @par1" & _
"when 4 then @par1" & _
"when 5 then @par1" & _
"end" & _
"where bnumber = @bnum and hraciden = @pd and league = @lm and rownumber in (1,2,3,4,5)"
.CommandType = CommandType.Text
.Parameters.AddWithValue("@par1", Team1Box.SelectedItem.ToString)
.Parameters.AddWithValue("@bnum", currentButton.Tag)
.Parameters.AddWithValue("@pd", Convert.ToInt16(playDayBox.SelectedItem))
.Parameters.AddWithValue("@lm", LeagueBox.SelectedItem.ToString)
End With
Try
MysqlConn.Open()
MyCommand.ExecuteNonQuery()
MysqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Using
End Using
你能指出我关于命令文本的正确方向吗?或者建议另一种解决方案?提前致谢!
最佳答案
在该代码执行后,您实际上查看过该 CommandText
的内容吗?我敢打赌不会。为什么这不是你做的第一件事?查看正在执行的 SQL,而不是构建该 SQL 的代码。这不是你想的那样。我建议您使用 XML 文字来创建该 SQL 代码。
关于mysql - 通过 VB.net 中的多个条件的一个查询在 MySQL 中进行多次更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25025187/