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.
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
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)
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