On Fri, 9 Apr 2004 15:15:24 -0400, "Eric Carr" <(E-Mail Removed)> wrote:
¤ I have been trying to create a table in an Access database via a VB.NET
¤ program and I am running into a problem defining an autoincrement field. I
¤ am getting an error saying "Property 'Item' is 'ReadOnly'" on the line that
¤ SHOULD be turning this property on for the ID field. Does any one have any
¤ suggestions on how to do this in .NET?
¤
¤ The code that I am using is:
¤ Dim cat As Catalog = New Catalog
¤ Dim tblNew As ADOX.Table = New ADOX.Table
¤ Dim colNew As ADOX.Column = New ADOX.Column
¤
¤ cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
¤ "Data Source=Reservations.mdb;" & _
¤ "Jet OLEDB:Engine Type=5")
¤
¤ ' Create a new Table object.
¤ With tblNew
¤ .Name = "tblCabin"
¤
¤ ' Create fields and append them to the columns collection of the new
¤ Table object.
¤
¤ With .Columns
¤ .Append("ID", DataTypeEnum.adInteger)
¤ .Item("ID").ParentCatalog = cat
¤ .Item("ID").Properties("AutoIncrement") = True '
¤ This is the line that generates the error
¤ .Append("Name", DataTypeEnum.adVarWChar, 50)
¤ .Append("NameShort", DataTypeEnum.adVarWChar, 10)
¤ End With
¤ End With
¤
¤ ' Add the new Table to the Tables collection of the database.
¤ cat.Tables.Append(tblNew)
¤
You should include the Value property:
Item("ID").Properties("AutoIncrement").Value = True
In addition, some of these properties may need to be set *before* appending the column to the
Columns collection.
Paul ~~~
(E-Mail Removed)
Microsoft MVP (Visual Basic)