是否可以更新某个列值并使用2个不同的表删除它?

时间:2016-01-07 08:26:51

标签: mysql datagridview mysql-workbench vb.net-2010

  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

我要做的是在第一个查询中,它将在第0列的blist表中更新。在第二个查询中,它将删除返回列表中的选定行。

1 个答案:

答案 0 :(得分:0)

您可以根据需要执行任意数量的查询。你把你的查询字符串放在一起:

"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 & "'"

然后你可以一起执行这两个命令。