The best way to achieve this is reload the data grid view. Here is the code that explains how to do it
Private Sub refreshDatagrid()
Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=reerp;User ID=root;Password=root;")
Dim sql As MySqlCommand = New MySqlCommand("SELECT * FROM users", con)
Dim ds As DataSet = New DataSet()
Dim DataAdapter1 As MySqlDataAdapter = New MySqlDataAdapter()
con.Open()
DataAdapter1.SelectCommand = sql
DataAdapter1.Fill(ds, "Users")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Users"
con.Close()
End Sub
now once you have added data to your grid then just call this method again. here is and example of how you do it
Dim query As String
Dim con As MySqlConnection = New MySqlConnection("data source=localhost;database=reerp;user id=root;password=root;")
query = "insert into users (username,password,first_name,last_name,role) values('"
query = query + tb_username.Text + "','" + tb_password.Text + "','" + tb_firstname.Text + "','" + tb_lastname.Text + "','" + ComboBox_role.Text + "');"
con.Open()
Dim cmd As MySqlCommand = New MySqlCommand(query, con)
Dim i As Integer = cmd.ExecuteNonQuery()
If (i > 0) Then
lblMsg.Text = "record is successfully inserted"
refreshDatagrid()
Else
lblMsg.Text = "record is not inserted"
End If
con.Close()
';DROP Table Branches;--in your street address field... or don't if you don't want to restore that table from backup. - Joel Coehoorn