Results 1 to 3 of 3

Thread: ADO and adding fields. or something...

  1. #1
    Guest

    Unhappy

    How do I use ADO to add values to a DB??
    if I had a field called

    PageID
    and a field called
    Content

    How would I add "Hello" to the PageID, and "hehehe" to the content field?

    I am not using the control, I am using a reference to ADO 2.5

  2. #2
    Junior Member
    Join Date
    Aug 2000
    Location
    Manila, Philippines
    Posts
    16
    Assuming you have an Access 97 database 'C:\MyDB.mdb',
    and that database has a table named 'MyTable' with the
    fields 'PageID' and 'Content', this is one way to do it:

    Dim cnn As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim strConnect As String
    Dim strQuery As String

    Set cnn = New ADODB.Connection
    Set cmd = New ADODB.Command

    'Create the connection string.
    strConnect = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
    "Persist Security Info=False;Data Source=C:\MyDB.mdb"

    'Open a connection to the database.
    cnn.Open strConnect

    'Create the query string.
    strQuery = "insert into MyTable (PageID, Content) " & _
    "values ('Hello', 'hehehe')"

    'Create the insert query.
    Set cmd.ActiveConnection = cnn
    cmd.CommandType = adCmdText
    cmd.CommandText = strQuery

    'Execute the insert query.
    cmd.Execute

    'Close the connection to the database.
    cnn.Close

  3. #3
    Guest
    Ok, Thanks very much,
    I forget all about using SQL....

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width