For k As Integer = Me.DataGridView1.SelectedRows.Count - 1 To 0 Step -1
Dim Query1 As String
Query1 = "Update librarydb.blist SET quantity=(quantity + 1) where quantity = '" & Me.DataGridView1.SelectedRows(k).Cells(0).Value.ToString & "'"
command1 = New MySqlCommand(Query1, MysqlConn1)
SDA1.SelectCommand = command1
SDA1.Fill(dbDataSet1)
bSource1.DataSource = dbDataSet1
Me.DataGridView1.DataSource = bSource1
SDA1.Update(dbDataSet1)
Dim Query2 As String
For j As Integer = Me.DataGridView1.SelectedRows.Count - 1 To 0 Step -1
Query2 = "delete from returnlist where student_id= '" & Me.DataGridView1.SelectedRows(j).Cells(1).Value.ToString & "'"
command1 = New MySqlCommand(Query1, MysqlConn1)
SDA1.SelectCommand = command1
SDA1.Fill(dbDataSet1)
bSource1.DataSource = dbDataSet1
Me.DataGridView1.DataSource = bSource1
SDA1.Update(dbDataSet1)
Next
Next
我想做的是在第一个查询中它将在 blist 表的第 0 列中更新。在第二个查询中它将删除 returnlist 表中的选定行。
最佳答案
您可以执行任意数量的查询。您可以像这样组合查询字符串:
"UPDATE tableA set fieldA = value; " +
"DELETE tableB WHERE fieldB = value"
因此您可以放置多个查询并执行它们,您需要用分号分隔它们。
因此,您可以将 2 个查询组合到一个查询变量中:
Dim Query As String
Query = "delete from returnlist where quantity= '" & Me.DataGridView1.SelectedRows(k).Cells(0).Value.ToString & "'; " &
"delete from returnlist where quantity= '" & Me.DataGridView1.SelectedRows(k).Cells(0).Value.ToString & "'"
然后您可以同时执行这两个命令。
关于mysql - 是否可以使用 2 个不同的表更新某个列值并删除它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34650386/