Updating Records in MS Access Using VB.Net

0
214

This tutorial is all about Updating Records in MS Access Using VB.Net. In this post i will teach you on Updating Records in MS Access Using VB.Net. So let’s get started:

As a continuation of this tutorial. We will use the Displaying Data Table Records in Datagridview using VB.Net

  • First, Design your Form like this one below.
    Add another Button. Name it “Update

  • After designing the form. Click the Update Button and add this following codes.
  1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  2. Try
  3. Sql = "UPDATE tblitems SET ITEMNAME='" & TextBox1.Text & "',BRAND= '" & TextBox2.Text & "', " & _
  4. " PRICE='" & TextBox3.Text & "' WHERE ID = " & Me.Text
  5. Myconnection.Open()
  6. With dbcmd
  7. .CommandText = Sql
  8. .Connection = Myconnection
  9. End With
  10.  
  11. result = dbcmd.ExecuteNonQuery
  12. If result > 0 Then
  13. MsgBox("New Record has been Updated!")
  14. Myconnection.Close()
  15. Call Button1_Click(sender, e)
  16. cleartextfields()
  17.  
  18. Else
  19. MsgBox("No Record has been Updated!")
  20. End If
  21.  
  22. Catch ex As Exception
  23. MsgBox(ex.Message)
  24. Finally
  25. Myconnection.Close()
  26.  
  27. End Try
  28. End Sub
  • After that, Add this following Sub in the Public Class Form1.
    1. Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    2. Me.Text = DataGridView1.CurrentRow.Cells(0).Value.ToString
    3. TextBox1.Text = DataGridView1.CurrentRow.Cells(1).Value.ToString
    4. TextBox2.Text = DataGridView1.CurrentRow.Cells(2).Value.ToString
    5. TextBox3.Text = DataGridView1.CurrentRow.Cells(3).Value.ToString
    6. End Sub
  • Then Click F5 to Run the Program.
    Output.
     

If you have any comments or suggestions about on Updating Records in MS Access Using VB.Net, please feel free to contact our webpage.

Download Updating Records in MS Access Using VB.Net Here

Other Articles Readers might read:

 

 

 

Facebook Comments
(Visited 232 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here