Results 1 to 4 of 4

Thread: appending field to recordset

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Location
    ILLINOIS
    Posts
    23

    appending field to recordset

    ADO HELP:

    Dim rst As New ADODB.Recordset

    rst.Fields.Append "xx1", adInteger
    rst.Fields.Append "xx2", adChar, 5
    rst.Open "test",strcon,adopendynamic,adlockoptimistic,adcmdtable

    rst.addnew "xx1","test"
    rst.update

    get an error on rst.addnew "Item cannot be found in the collection corresponding to the requested name or ordinal."

    it seems that the xx1 was not appended.
    So how will the fields show up in the database. Can someone give me sample code to append fields to my database.

    and

    how do you create a mdb database in ADO?
    in dao it is simply the createdatabase(path)
    in ADO how do you do this?

  2. #2
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    FL
    Posts
    258
    You can use ADOX to create a DB, here is an example.

    VB Code:
    1. Private Sub Command1_Click()
    2.     Set cat = New ADOX.Catalog
    3.     Set tbl = New ADOX.Table
    4.  
    5.     cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\newDB.mdb"
    6.    
    7.     With tbl
    8.       .name = "TestTable"
    9.       ' Create fields and append them to the
    10.       ' Columns collection of the new Table object.
    11.       With .Columns
    12.          .Append "ID COLUMN"
    13.          .Append "SetName", adVarWChar, 255
    14.          .Append "SetVal", adVarWChar, 255
    15.          .Append "Description", adVarWChar, 255
    16.       End With
    17.    End With
    18.    
    19.    ' Add the new Table to the Tables collection of the database.
    20.    cat.Tables.Append tbl
    21.    
    22.    Set cat = Nothing
    23.    Set tbl = Nothing
    24.    
    25. End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Location
    ILLINOIS
    Posts
    23
    thanks,

    but anybody who can answer my first question using ADO, that is appending fields, also

    is there a way to copy a table and contents of one access database and add that table and contents to another database.
    in dao it is just using the tableder.connect and tabledef.sourcetablename properties. how can we do this with ado?

    again thanks

  4. #4
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    FL
    Posts
    258
    I remember being part of a thread with same problem last week.
    Check out this thread, it may help.

    http://www.vbforums.com/showthread.p...threadid=94298

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