Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15463

Append table to ADO database

$
0
0
I'm a complete dummy when it comes to databases, so I thought I'd try out the simple ADO database code recommended by ChrisE in this VB.Net forum thread (post #48). It creates an .mdb file successfully but fails when I try to append a Table.
Code:

Imports ADOX
[....]
      'create a connection string
        Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mdbFileName

        'replace existing file if any
        IO.File.Delete(mdbFileName)

        'create catalog
        Dim cat As New Catalog()
        cat.Create(connectionString)

      'create a table with columns
        Dim tbl1 As New Table
        tbl1.Columns.Append("col1", DataTypeEnum.adInteger, 4)
        tbl1.Columns.Append("col2", DataTypeEnum.adLongVarWChar, 255)

        'add the table to the tables collection
        Dim obj As Object = DirectCast(tbl1, Object)
        cat.Tables.Append(obj)

The Append statement in the last line always throws an exception:
System.Runtime.InteropServices.COMException: 'Table ID is invalid.'
even when I comment out one or both columns. Can anyone tell me what is going wrong here?

BB

Viewing all articles
Browse latest Browse all 15463

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>