I want to add 12 players in 1 transaction only. My codes here can only save 1 player.
Here's my codes:
Private Sub savebtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles savebtn.Click
Dim conn As MySqlConnection
Dim myCommand As New MySqlCommand
Dim commandB As MySqlCommandBuilder
Dim data As MySqlDataAdapter
Dim query As String = "SELECT * FROM basketplayer b;"
Dim myconnstring As String
Dim comm As String
Dim value As String
value = TeamNameTextBox.Text & "', '" & Player1NumberTextBox.Text & "', '" & Player1NameTextBox.Text
'11 more textboxes that contains players
myconnstring = "datasource=localhost;username=root;password=monchito;database=newscoring;"
comm = "INSERT INTO `basketplayer` (`team`, `plnum`, `playernam`, `pts`, `throw`, `foul`) VALUES ('" & value & "', '0', '0', '0');"
conn = New MySqlConnection(myconnstring)
Try
conn.Open()
data = New MySqlDataAdapter(query, conn)
commandB = New MySqlCommandBuilder(data)
Dim res As New MySqlParameter
res.Value = commandB
myCommand.CommandText = comm
myCommand.Connection = conn
Try
'1 Player that has saved in this command. Only the first entry.
myCommand.ExecuteNonQuery()
MessageBox.Show("Players successfully added!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
newbtn.PerformClick() 'all textbox are cleared
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
conn.Dispose()
End Try
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
conn.Dispose()
End Try
End Sub