Insert data into MS-Access

Insert data into MS-Access in VB.net


This is an example which is best and very simple for inserting to an MS Access database.

1. First of all add a textbox and button.
2. Add these namespaces into the program before the start of the class

Imports System.Data
Imports System.Data.OleDb


3. Declare these variables in the form

Dim conn As OleDb.OleDbConnection
Dim cmd As OleDb.OleDbCommand


4. Add these on the button click event

cmd = New OleDb.OleDbCommand("insert into Table1 values(' " + TextBox1.Text + " ')", conn)
cmd.ExecuteNonQuery()

add this form load
Dim con As String = "Provider=Microsoft.JET.oledb.4.0;Data Source=H:\SPM\name.mdb"
conn = New OleDb.OleDbConnection(con)
conn.Open()


NOTE:Please dont forget to change database name and table name as per ur table.


Comments

Author: iloveu17 Jul 2009 Member Level: Bronze   Points : 0

thanx... its rally working with these short codes... thanx a lot...

Author: Sundar11 Oct 2009 Member Level: Bronze   Points : 1

thanks its a very good help for the begginer level, application developer thanks a lot

Guest Author: ndahimana05 Mar 2013

it is just correct



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: