Home
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
 
 
 
 
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-2001 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated