2011-03-29 5 views
1

J'utilise VB.NET avec une base de données MySQL. Je veux mettre à jour ce code pour le faire tout en UN SQL au lieu de TROIS. Quelqu'un sait comment?MISE À JOUR MySQL en utilisant VB.NET

Voici le code que je utilise, fonctionne très bien, mais trop lent avec plusieurs lignes ...

If count3 = "1" Then 

    Dim myCommand As New MySqlCommand 
    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 

Répondre

1

Ceci est juste ma conjecture, mais vous pouvez essayer coller les trois instructions SQL ensemble; à peu près comme

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

Notez le point-virgule qui sépare les instructions.

+0

j'ai pu le faire comme ceci: – BooMGiRL

+0

SQL = "employés UPDATE SET emprole1 = « " & val2 & " 'OÙ emprole1 ='" & val1 & "' ;" SQL & = "employés UPDATE SET emprole2 = « " & val3 & "'O WH emprole2 ='" & val2 " SQL & =" MISE À JOUR des employés SET emprole3 = '"& val4 &"' O WH emprole3 = '"& val3 &"' – BooMGiRL

+0

@BooMGiRL Great –