I'm a beginner in using ado
My application needs to create a DB at runtime
Can someone give me an example on how to create tables and fields ?
Thank You all & excuse me if my english is bad
Printable View
I'm a beginner in using ado
My application needs to create a DB at runtime
Can someone give me an example on how to create tables and fields ?
Thank You all & excuse me if my english is bad
sample
VB Code:
Option Explicit Dim cat As ADOX.Catalog Dim tbl As ADOX.Table Private Sub Command1_Click() Set cat = New ADOX.Catalog Set tbl = New ADOX.Table ' create the db cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\newDB.mdb" With tbl .Name = "TestTable" ' Create fields and append them to the ' Columns collection of the new Table object. With .Columns .Append "ID COLUMN" .Append "SetName", adVarWChar, 255 .Append "SetVal", adVarWChar, 255 .Append "Description", adVarWChar, 255 End With End With ' Add the new Table to the Tables collection of the database. cat.Tables.Append tbl Set cat = Nothing Set tbl = Nothing End Sub
You need to add a reference to 'Microsoft ADO Ext. X.X For DLL And Security' in order to use the sample.
:)
You can also create tables using SQL
VB Code:
'add a table with some fields sql = "CREATE TABLE TestTable (ID COUNTER, SetName TEXT(50), SetVal TEXT(255), Description TEXT(255))" db.Execute sql