Databases Reference
In-Depth Information
3. Append some columns to the Key object's Columns collection.
4. Append the Key object to the Index object's Keys collection.
Here is an example:
Sub ADOCreatePrimaryKey( )
Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table
Dim pk As New ADOX.Key
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=d:\temp\ADOXExample.mdb;"
Set tbl = cat.Tables("Newtable")
' Create the Primary Key
pk.Name = "PrimaryKey"
pk.Type = adKeyPrimary
pk.Columns.Append "Column1"
' Append the Key object to the Keys collection of Table
tbl.Keys.Append pk
End Sub
18.1.6 Creating a Query
To create a query, we use the ADO Command object to create a new ADO command.
This can be appended to the Views (or Procedures ) collection of the catalog to create a
new query. Its syntax is:
ViewsObj .Append Name , Command
where Name is a string containing the name of the object, and Command is a Command
object.
Here is an example:
Sub CreateQuery( )
Dim cat As New ADOX.Catalog
Dim cd As New ADODB.Command
Dim sSQL As String
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=d:\temp\ADOXExample.mdb;"
sSQL = "SELECT * FROM Newtable"
cd.CommandText = sSQL
cat.Views.Append "Newquery", cd
Search WWH ::




Custom Search