Creating or changing tables in an access database
-
Continuing to slug through a VB6 to VS2008 conversion. In VB6 I was able to modify Access databases and add tables using a bit of code similar to the following (simplified for explanation)
MyTableDef = MyDb.CreateTableDef(tblName)
' record type
For i = 1 To UBound(Fields)
MyField = MyTableDef.CreateField(Fields(i), FieldType(i), Size(i))
MyTableDef.Fields.Append(MyField)
Next
MyDb.TableDefs.Append(MyTableDef)
MyDb.Close()
Exit Sub
</pre>Fields, FieldType and Size are arrays with a name, length and type of field to be created and appended.
I would like to duplicate this type of functionality using AD0 in VS2008. I know I can do it with a direct SQL command, but those could get real long and ugly. With this method I just add fields to an array and send them to this function.
Any suggestions?
Thanks in advance
-
Continuing to slug through a VB6 to VS2008 conversion. In VB6 I was able to modify Access databases and add tables using a bit of code similar to the following (simplified for explanation)
MyTableDef = MyDb.CreateTableDef(tblName)
' record type
For i = 1 To UBound(Fields)
MyField = MyTableDef.CreateField(Fields(i), FieldType(i), Size(i))
MyTableDef.Fields.Append(MyField)
Next
MyDb.TableDefs.Append(MyTableDef)
MyDb.Close()
Exit Sub
</pre>Fields, FieldType and Size are arrays with a name, length and type of field to be created and appended.
I would like to duplicate this type of functionality using AD0 in VS2008. I know I can do it with a direct SQL command, but those could get real long and ugly. With this method I just add fields to an array and send them to this function.
Any suggestions?
Thanks in advance
If you absolutely must use the same functionality, add a reference to DAO. The TableDef and Fields objects are defined there.