How do I create an AutoIncrement column with ADOX ?
From: harry (harry_at_nospam)
Date: 02/29/04
- Previous message: harry: "How do I create an AutoIncrement column with ADOX ?"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 29 Feb 2004 19:32:56 +1100
This post originally posted in microsoft.public.data.oledb however it seems
to have dissapeared? So reposted...
Hi,
I'm trying to create AutoIncrement column in a new Access database table
via ADOX.
I am using MSDN sample code however I still receive error: Property 'Item'
is 'ReadOnly'
The line triggering the error is:
.Item("ContactId").Properties("AutoIncrement") = True
I'm using MDAC 2.8 and VB.NET
How do I create AutoIncrement column when creating new table using ADOX ?
Thanks
Harry
This is the Sample I tried...
Sub CreateAutoNumberField(strDBPath As String)
Dim catDB As ADOX.Catalog
Dim tbl As ADOX.Table
Set catDB = New ADOX.Catalog
' Open the catalog.
catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDBPath
Set tbl = New ADOX.Table
With tbl
.Name = "Contacts"
Set .ParentCatalog = catDB
' Create fields and append them to the
' Columns collection of the new Table object.
With .Columns
.Append "ContactId", adInteger
' Make the ContactId field auto-incrementing.
.Item("ContactId").Properties("AutoIncrement") = True
.Append "CustomerID", adVarWChar
.Append "FirstName", adVarWChar
.Append "LastName", adVarWChar
.Append "Phone", adVarWChar, 20
.Append "Notes", adLongVarWChar
End With
End With
' Add the new Table to the Tables collection of the database.
catDB.Tables.Append tbl
Set catDB = Nothing
End Sub
- Previous message: harry: "How do I create an AutoIncrement column with ADOX ?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|