Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse ADO to insert records into a database
KeywordsADO, database, insert
CategoriesDatabase
 
Create an SQL INSERT statement. Use the Connection object's Execute method to execute the statement.
 
Dim statement As String
Dim conn As ADODB.Connection

    ' db_file is the Access database's file name.
    ' Open a connection.
    Set conn = New ADODB.Connection
    conn.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & db_file & ";" & _
        "Persist Security Info=False"
    conn.Open

    ' Compose the INSERT statement.
    statement = "INSERT INTO Addresses " & _
        "(Name, Street, City, State, Zip) " & _
        " VALUES (" & _
        "'" & txtName.Text & "', " & _
        "'" & txtStreet.Text & "', " & _
        "'" & txtCity.Text & "', " & _
        "'" & txtState.Text & "', " & _
        "'" & txtZip.Text & "'" & _
        ")"

    ' Execute the statement.
    conn.Execute statement, , adCmdText

    ' Close the connection.
    conn.Close
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated