开发者

UPDATE MySQL using VB.NET

I am using VB.NET with a MySQL database. I want to update this code to do it all in ONE SQL instead of THREE. Anyone know how?

Here's the code I'm using, works fine but too slow with multiple lines...

If count3 = "1" Then

    Dim myCommand As New M开发者_如何学CySqlCommand
    Dim myAdapter As New MySqlDataAdapter
    Dim SQL As String
    myCommand.Connection = conn
    myAdapter.SelectCommand = myCommand
    SQL = "UPDATE employees SET emprole1 = '" & val2 & "' WHERE emprole1 = '" & val1 & "'"
    myCommand.CommandText = SQL
    myCommand.ExecuteNonQuery()
    SQL = "UPDATE employees SET emprole2 = '" & val3 & "' WHERE emprole2 = '" & val2 & "'"
    myCommand.CommandText = SQL
    myCommand.ExecuteNonQuery()
    SQL = "UPDATE employees SET emprole3 = '" & val4 & "' WHERE emprole3 = '" & val3 & "'"
    myCommand.CommandText = SQL
    myCommand.ExecuteNonQuery()

End If


This is just my guess, but you could try gluing all three SQL statements together; pretty much like

SQL = "update employees set ... ; update employees set ... ;";

Note the semicolon that separates statements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜