Results 1 to 4 of 4

Thread: add table, then add data *RESOLVED*

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904

    add table, then add data *RESOLVED*

    I have successfully added a new table to an existing db, using the ADOX "catalog". I am also able to add new data to an existing table using ADO data table statements. What I CANNOT figure out how to do is to combine the two so that I can create a new table and then populate it.

    My "add table" code, which works fine to add the table, is as follows, but I can't figure out how to (1) close the table so I can reopen it to add data, or (2) add data in some other way.

    I think I can figure out how to do it using SQL, but I really don't want to do it that way. I'm a big fan of ADO / ADOX and would like to stick to those methods and avoid SQL.

    Code:
        Dim tbl As New Table
        Dim cat As New ADOX.Catalog
        Dim rsNEW As ADODB.Recordset
        '
        ' Open the catalog
        '
        cat.ActiveConnection = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source=" & App.Path & "\DB1.mdb"
        '
        ' set info for new table
        '
        tbl.Name = "NewTable"
        tbl.Columns.Append "int1", adInteger
        tbl.Columns.Append "int2", adInteger
        tbl.Columns.Append "text1", adVarWChar, 50
        '
        ' append table to the catalog (i.e. add table to db)
        '
        cat.Tables.Append tbl
    the code I use to add data to an existing table, which also works, is as follows, but I can't run it after the above because I can't create the rs, since it's already open, and I can't figure out how to otherwise add data.

    Code:
        Set rsNEW = New ADODB.Recordset
        rsNEW.Open "NewTable", cn, adOpenKeyset, adLockPessimistic, adCmdTable
        With rsNEW
            .AddNew
            .Fields("int1") = 13
            .Fields("int2") = 14
            .Fields("text1") = "hi --- I'm a new data field"
            .Update
        End With
    any help appreciated.
    Last edited by phinds; May 23rd, 2003 at 10:01 AM.

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