My App updates two tables at once(username from accounts and orders), but if second tables does not contain the same record(no orders) then it only updates first table(accounts)

This code works, but I am trying to merge them into a single string

' Multi: True = Update Both Tables
' Multi: False= Update Single Table
If Multi = True Then
        SQL = "UPDATE accounts,orders" & _
                   " SET accounts.username = 'new_username',accounts.password = 'blabla'" & _
                   ",orders.username='new_username'" & _
                   " WHERE accounts.username = 'old_username' AND orders.username='old_username'" & _
                   " OR accounts.username = 'old_username'"
Else
        SQL = "UPDATE accounts" & _
                   " SET username = 'new_username',password = 'blabla'" & _
                   " WHERE username = 'old_username'"
End If

I tried to merge two SQLStrings but it updates all rows in one column(usernames) on the second table(orders)

SQL = "UPDATE accounts,orders" & _
                   " SET accounts.username = ''new_username",accounts.password = 'blabla'" & _
                   ",orders.username='new_username'" & _
                   " WHERE (accounts.username = 'old_username' AND orders.username='old_username')" & _
                   " OR accounts.username = 'old_username'"

Use two update statements in your command text. From what I can tell your first update is the same but under a certain condition you have a second update. So do something like:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim SQL As String
		SQL = "Update aTable Set aColumn = 'aValue'"

		If (True) Then
			SQL += Environment.NewLine & _
				"Update anotherTable Set anotherColumn = 'anotherValue'"
		End If

	End Sub

Use two update statements in your command text. From what I can tell your first update is the same but under a certain condition you have a second update. So do something like:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim SQL As String
		SQL = "Update aTable Set aColumn = 'aValue'"

		If (True) Then
			SQL += Environment.NewLine & _
				"Update anotherTable Set anotherColumn = 'anotherValue'"
		End If

	End Sub

I didn't realize that you could do more queries at one time.

Thanks snake, you've been very helpful

This question has already been answered. Start a new discussion instead.