How to update record into access database using VB.Net

 

Introduction

In this article i will tell you How to update record into access database using VB .Net.

History

In the Previous articles i explained How to create connection stringhow to insert record into access database using c#.nethow to update record into access database using c#.nethow to delete record from access database using c#.netwhich namespace is used for membership class, how to insert record into access database using vb.net and many more about VB.Net.

Step 1.

Use below namespace.

Imports System.Data.OleDb

Step 2.

Write below code on click event of the button.

Try
    Dim con As New OleDbConnection("YourConnectionString")
    con.Open()
    Dim cmd As New OleDbCommand("update table1 set name='Gorav Verma',age='23',class='12th' where id='10001'", con)
    cmd.ExecuteNonQuery()
    lbl_msg.Text = "Record Updated Successfully."
    con.Close()
Catch
    lbl_msg.Text = "Error Occured."
End Try

Below is the explanation.

Line 1.

Create connection with your database. Replace "YourConnectionString" with your own connection string.

Line 2.

Open Your Connection.

Line 3.

Create Sql command for updating records into table1. Here i am updating the records into columns "name","age","class"of  table "table1" where id='10001'. Also pass your connection in oledbcommand.

Line 4.

Execute Query.

Line 5.

Show Message if record updated successfully.

Line 6.

Close the connection.

Give your Valuable Comments.
comments powered by Disqus
 
Follow me on twitter
About Me
Harpreet Singh
I began programming with C++ when i was 17. Then at the middle of my study .NET came. Then I began to read C# and VB.NET. By the time i learnt SQL and ASP.NET, and developed some websites such as news portals that are active now. Currently i am running my own Software company.
More Articles