>> Does anyone have code that creates a table using ADO? I'm just looking to
>> create a table with int32, datatime and index. Any code on this.
[quoted text clipped - 12 lines]
> Create a reference to the ADOX library, "Microsoft ADO Ext 2.5 for DDL and
> Security" and start playing. Just goggle the inet for usage examples.
Hi,
In VB I add a reference to "Micrsoft ActiveX Data Objects 2.8 library",
which is msado15.dll. The version doesn't matter much. The trick is finding
a connection string for you DBMS. You may have to search on the Internet for
examples for you DBMS. Below is for SQL Server. In the example below I test
for the existence of the table MyTable. If it exists, I delete it. Then I
create it. The T-SQL statements are passed as strings to the ADO command
object. Another trick is taking T-SQL statements and enclosing them in
quotes, getting all the spaces, commas, etc. correct. An example:
===================
strDB = "MyDatabase"
strServer = "MyServer"
strInstance = "MyInstance"
' Construct connection string for SQL Server.
' If there is no instance, omit "\" and strInstance.
' This assumes integrated Windows authentication.
strDBConnect = "DRIVER=SQL Server;" _
& "Trusted_Connection=Yes;" _
& "DATABASE=" & strDB & ";" _
& "SERVER=" & strServer & "\" & strInstance
' Connect to SQL Server with ADO Connection object.
Set adoConnection = New ADODB.Connection
adoConnection.ConnectionString = strDBConnect
adoConnection.Open
' Setup ADO command object.
Set adoCommand = New ADODB.Command
adoCommand.ActiveConnection = adoConnection
adoCommand.CommandType = adCmdText
' If table MyTable exists, delete it.
strSQL = "IF EXISTS " _
& "(" _
& "SELECT TABLE_NAME " _
& "FROM INFORMATION_SCHEMA.TABLES " _
& "WHERE TABLE_NAME = 'MyTable'" _
& ") " _
& "DROP TABLE MyTable"
adoCommand.CommandText = strSQL
adoCommand.Execute
' Create table MyTable.
strSQL = "CREATE TABLE MyTable " _
& "(" _
& "Field1Name INTEGER NOT NULL, " _
& "Field2Name VARCHAR(24) NULL, " _
& "Field3Name DATETIME NULL, " _
& "Field4Name MONEY NULL, " _
& "Field5Name BIT NOT NULL, " _
& "Field6Name VARCHAR(50) NULL, " _
& ")"
adoCommand.CommandText = strSQL
adoCommand.Execute

Signature
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net