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("Pro vider=Microsoft .Jet.OLEDB.4.0; " & _
"Data Source=Reservat ions.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.ad Integer)
.Item("ID").Par entCatalog = cat
.Item("ID").Pro perties("AutoIn crement") = True '
This is the line that generates the error
.Append("Name", DataTypeEnum.ad VarWChar, 50)
.Append("NameSh ort", DataTypeEnum.ad VarWChar, 10)
End With
End With
' Add the new Table to the Tables collection of the database.
cat.Tables.Appe nd(tblNew)
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("Pro vider=Microsoft .Jet.OLEDB.4.0; " & _
"Data Source=Reservat ions.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.ad Integer)
.Item("ID").Par entCatalog = cat
.Item("ID").Pro perties("AutoIn crement") = True '
This is the line that generates the error
.Append("Name", DataTypeEnum.ad VarWChar, 50)
.Append("NameSh ort", DataTypeEnum.ad VarWChar, 10)
End With
End With
' Add the new Table to the Tables collection of the database.
cat.Tables.Appe nd(tblNew)
Comment