Vb.net Access Database Example -
Private Sub ClearInputs() txtFirstName.Clear() txtLastName.Clear() txtEmail.Clear() txtAge.Clear() txtFirstName.Focus() End Sub Private Sub dgvUsers_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvUsers.CellClick If e.RowIndex >= 0 Then Dim row As DataGridViewRow = dgvUsers.Rows(e.RowIndex) txtFirstName.Text = row.Cells("FirstName").Value.ToString() txtLastName.Text = row.Cells("LastName").Value.ToString() txtEmail.Text = row.Cells("Email").Value.ToString() txtAge.Text = row.Cells("Age").Value.ToString() End If End Sub Here's the complete form code:
Private Function ValidateInputs() As Boolean If String.IsNullOrWhiteSpace(txtFirstName.Text) Then MessageBox.Show("First Name is required") Return False End If vb.net access database example
Private Sub btnInsert_Click(sender As Object, e As EventArgs) Handles btnInsert.Click If ValidateInputs() = False Then Exit Sub Dim query As String = "INSERT INTO Users (FirstName, LastName, Email, Age) VALUES (@FirstName, @LastName, @Email, @Age)" Private Sub ClearInputs() txtFirstName
Dim query As String = "UPDATE Users SET FirstName=@FirstName, LastName=@LastName, Email=@Email, Age=@Age WHERE UserID=@UserID" Age) VALUES (@FirstName
Return True End Function Add this to the Update button: