Click here to Skip to main content
Click here to Skip to main content

Insert, Update, Delete & Search Values in MS Access 2003 with VB.NET 2005

, 9 Jun 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
How to Insert, Update, Delete & Search Values in MS Access 2003 with VB.NET 2005

Download WithAccess - 143.91 KB

Shahzad Mahmood
Netsol Technologies Limited
Safari Villas,
Rawalpindi, Pakistan


This article and sample covers that "How to Insert, Update, Delete and Search Values to/from MS Access database 2003 with VB.NET 2005", Although VB.NET 2005 gives lot more methodologies to do this same job but I find this more easier, simplest and understandable for a beginner.


Learner must have little bit programming experience of VB.NET 2005 and MS Access 2003

Using the Code

Follow the steps:

  1. Create a VB.NET 2005 Windows Project,
  2. Place 3 Labels on form.
  3. Place 3 TextBoxes, Rename them txtAu_ID, txtAuthor, txtSearchResult
  4. Place 4 Buttons, Rename them btnInsert, btnUpdate, btnDelet, btnSearch
  5. Create MS Access Database "TestDB.mdb"
  6. Create a Table "Authors" with 2 fields "Au_ID" and "Author"

Copy and Pate the following code:

Imports System.Data

Imports System.Data.OleDb 

Public Class Form1 

    Dim cnnOLEDB As New OleDbConnection

    Dim cmdOLEDB As New OleDbCommand
    Dim cmdInsert As New OleDbCommand

    Dim cmdUpdate As New OleDbCommand

    Dim cmdDelete As New OleDbCommand

    Dim strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & 
        System.Environment.CurrentDirectory & "\TestDB.mdb" 

    Private Sub Form1_Load(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles MyBase.Load 

        cnnOLEDB.ConnectionString = strConnectionString


    End Sub 

    Private Sub btnSearch_Click(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles btnSearch.Click 

    txtAearchResult.Text = "" 

    Dim vSearch As String = InputBox("Enter Integer number to search name:") 

    If vSearch <> "" Then 

        cmdOLEDB.CommandText = "SELECT Au_ID,
            Author FROM Authors WHERE Au_ID=" & CInt(vSearch) 

        cmdOLEDB.Connection = cnnOLEDB

        Dim rdrOLEDB As OleDbDataReader = cmdOLEDB.ExecuteReader

        If rdrOLEDB.Read = True Then
        txtAearchResult.Text &= rdrOLEDB.Item(0).ToString & " " & 


        Exit Sub



            "Record not found")

            Exit Sub 

        End If


        MsgBox("Enter search value.") 

        Exit Sub 

    End If 

    End Sub

    Private Sub btnInsert_Click(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles btnInsert.Click 

    If txtAu_ID.Text <> "" And txtAuthor.Text <> "" Then 

        cmdInsert.CommandText = "INSERT INTO Authors (Au_ID, Author) VALUES (" & 
            xtAu_ID.Text & ", '" & txtAuthor.Text & "');" 


         cmdInsert.CommandType = CommandType.Text

         cmdInsert.Connection = cnnOLEDB


         MsgBox(txtAu_ID.Text = "Record inserted.")"" 

         txtAuthor.Text = "" 


        MsgBox("Enter the required values:" & 
            vbNewLine & "1. Au_ID" & vbNewLine & "2.Author")

    End If 


    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles btnUpdate.Click

    If txtAu_ID.Text <> "" And txtAuthor.Text <> "" Then

        cmdUpdate.CommandText = "UPDATE Authors SET Author = '" & txtAuthor.Text & "' 
        WHERE Au_ID = " & txtAu_ID.Text & ";" 


        cmdUpdate.CommandType = CommandType.Text

        cmdUpdate.Connection = cnnOLEDB


        MsgBox(txtAu_ID.Text = "Record updated.")"" 

        txtAuthor.Text = "" 


        MsgBox("Enter the required values:" & vbNewLine & "1. Au_ID" & vbNewLine & 

    End If


    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles btnDelete.Click 

    If txtAu_ID.Text <> "" Then 

        cmdDelete.CommandText = "DELETE FROM Authors WHERE Au_ID = " &
            txtAu_ID.Text  & ";" 


        cmdDelete.CommandType = CommandType.Text

        cmdDelete.Connection = cnnOLEDB


        MsgBox(txtAu_ID.Text = "Record deleted.")"" 

        txtAuthor.Text = "" 



        MsgBox("Enter the required values:" & vbNewLine & "1. Au_ID") 

    End If


    End Sub

End Class

For further details send leave me a message on the messaged board below


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Member 3931606

Pakistan Pakistan
No Biography provided

Comments and Discussions

QuestionConnection Error PinmemberMember 111344556-Oct-14 22:56 
QuestioncnnOLEDB.Open error PinmemberMember 1081656513-May-14 16:15 
GeneralMy vote of 5 PinmemberVast is best21-Dec-12 5:14 
Questioncopy this code place of above coding its working...!!!! PinmemberHaresh Prajapati4-Dec-12 22:24 
QuestionAbout Search Button PinmemberHaresh Prajapati3-Dec-12 3:51 
QuestionI want to disable the message INSERT INTO Authors (Au_ID, Author,Gender)..... when i insert data in the form PinmemberSachinwei23-May-12 19:39 
QuestionHelp me how to have a perfect location of database on the project i publish PinmemberSachinwei22-May-12 20:30 
QuestionHelp PinmemberAmeeR-8922-May-12 1:31 
Questionupdate database Pinmemberbill clift23-Mar-12 8:10 
Questionneed help Pinmemberalom_9320-Feb-12 13:32 
GeneralMy vote of 5 Pinmembermanish100028-Sep-10 5:24 
Generalprint PinmemberMohamed Safi Samsudeen6-Jan-09 23:24 
GeneralRe: print PinmemberMohamed Safi Samsudeen11-Jan-09 23:47 
GeneralRe: print PinmemberMember 393160612-Jan-09 17:22 
GeneralRe: print PinmemberMohamed Safi Samsudeen14-Jan-09 21:54 
Generalfocus false PinmemberMohamed Safi Samsudeen12-Dec-08 4:20 
Generalexe file PinmemberMohamed Safi Samsudeen28-Nov-08 20:53 
GeneralRe: exe file PinmemberMember 393160630-Nov-08 20:38 
Follow the following steps:
Open Visual Studio
Create New Project
Point to Other Project Types
Select Setup and Deployment
Setup Project
You will see two panes
Select Application Folder from Left Side
Right Click on Right Pane and Select Add then Files - Here add your files if you want to add folder then fist Create a folder and open that folder and then add your files
Select User Desktop from Left
Right click on Right Pane and Select Create New Shortcut - Select the .exe from your application folder
Select User's Program Menu from Left
Right click on Right Pane If you want to create a folder then first create folder and then add the file

Then move to menu bar then Build Solution

Let it create the package

Try it, Best of luck
GeneralRe: exe file PinmemberMohamed Safi Samsudeen2-Dec-08 23:31 
GeneralRe: exe file PinmemberMember 39316063-Dec-08 0:53 
Generalhi PinmemberMohamed Safi Samsudeen10-Nov-08 23:47 
GeneralRe: hi PinmemberMember 393160611-Nov-08 1:12 
GeneralHi PinmemberMohamed Safi Samsudeen4-Nov-08 2:29 
GeneralRe: Hi PinmemberMember 39316064-Nov-08 18:01 
Generalhelp me Pinmembervprakashit22-Feb-13 14:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.1 | Last Updated 9 Jun 2008
Article Copyright 2008 by Member 3931606
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid