How to insert data in an access database from a VB.NET form

  • 15 years ago

    I am trying to Insert some data fields into a table in an access datbase usign a VB.Net form.
    The connection i am using is  looks like this

    Dim ConString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=""F:\Visual Studio 2005\Projects\ATM Banking System\NewBank.mdb"";"
            'provider to be used when working with access database
            Dim DBCon As New OleDb.OleDbConnection(ConString)




    Dim strsql As String = "SELECT [AccountNo] FROM Customer WHERE [PIN]='" & Login.txtPIN.Text & "' "

                Dim cm As New OleDb.OleDbCommand(strsql, DBCon)
                Dim dr As OleDb.OleDbDataReader

    I am able to read data from the access database, but i want to also add new records for transactions done.

    Can i please get some Advice
    Thank you

  • 15 years ago

    Hi chitterman

    u can also use reader for inser and updation operation

     Dim strsql As String = "insert command/ update command"

                Dim cm As New OleDb.OleDbCommand(strsql, DBCon)
                Dim dr As OleDb.OleDbDataReader

    for reading purpose ur using


    for insert or update or delete operation

    u can use

    cm.ExecuteNonQuery() ' No return type

    i hope u can understand where u did the mistake in ur coding


    Hari K

  • 15 years ago

    Hi mychitterman

    I am going to give you very good advice for you situation.

    as Khari Already mentoied that you can use DataReader for reading data from access. and for inserting use command objects ExecuteNonQuery Method.
    but suppose some time you need to insert two rows , one in different table and one in other table .

    like ATM Trasaction . Dabit and Cradit situation.

    Then you need to Use TRANSACTION object in VB.NET

    its very handy.

    ' Make the transaction.
    Dim trans As OleDb.OleDbTransaction = _

    you can read important articals
    URL :

  • 15 years ago

    hi King

     Thankyou for ur advise

     Mostly i was using under transaction when i was using more that one table operation

    and also ur article site
    also very helpful for me


    Hari K


Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint Exupéry