Well, there are a couple of different ways.
One is to use SQL Create Table syntax. A good basic reference is at:
[URL unfurl="true"]http://www.w3schools.com/sql/sql_create.asp[/url]
Or, you could use ADOX. To use ADOX, reference "Microsoft ADO Ext. 2.x for DDL and Security" and "Microsoft ActiveX Data Objects 2.x Library" under Project->References. Note: where the references have 2.x you will have a number, like 2.5. Then use this code (or similar):
Here is Microsoft's ADOX reference:
[URL unfurl="true"]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/admscadoapireference.asp[/url]
Hope this helps.
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
One is to use SQL Create Table syntax. A good basic reference is at:
[URL unfurl="true"]http://www.w3schools.com/sql/sql_create.asp[/url]
Or, you could use ADOX. To use ADOX, reference "Microsoft ADO Ext. 2.x for DDL and Security" and "Microsoft ActiveX Data Objects 2.x Library" under Project->References. Note: where the references have 2.x you will have a number, like 2.5. Then use this code (or similar):
Code:
Dim conn As ADODB.Connection
Dim tbl As ADOX.Table
Dim cat As ADOX.Catalog
Dim col As ADOX.Column
Set conn = New ADODB.Connection
'use your database and server names in connection string
conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=<database-name>;Data Source=<SQLServer-name>"
conn.CursorLocation = adUseClient
conn.Open
Set cat = New ADOX.Catalog
cat.ActiveConnection = conn
Set tbl = New ADOX.Table
Set col = New ADOX.Column
tbl.Name = "ADOXTest"
col.Type = adVarChar
col.DefinedSize = 30
col.Name = "Field1"
tbl.Columns.Append col
Set col = Nothing
Set col = New ADOX.Column
col.Type = adInteger
col.DefinedSize = 4
col.Name = "Field2"
tbl.Columns.Append col
cat.Tables.Append tbl
Set conn = Nothing
Set cat = Nothing
Set tbl = Nothing
Set col = Nothing
Here is Microsoft's ADOX reference:
[URL unfurl="true"]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/admscadoapireference.asp[/url]
Hope this helps.
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson