PC Review


Reply
Thread Tools Rate Thread

Creating table in Access database

 
 
Eric Carr
Guest
Posts: n/a
 
      9th Apr 2004
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)


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      10th Apr 2004
Hi Eric,

You are using ADO that can be used in VB.net (however what not), but it not
Ado.Net.
Most of us are not using Ado anymore (I use it to create an access database,
because that is impossible with AdoNet)

However your problem can, so have a look for Adonet.

Here is a link to the resource kit to have some samples for that and more.
(There is also a sample in it using ADO when you want to keep that)

http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing it

http://msdn.microsoft.com/vbasic/vbr...q/#installvdir

I hope this helps a little bit?

Cor


 
Reply With Quote
 
Paul Clement
Guest
Posts: n/a
 
      12th Apr 2004
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)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
automatically creating table links in access to new tables in sqlserver database Ruben Gouveia Microsoft Access VBA Modules 1 19th Dec 2009 04:48 AM
Creating a table link via ODBC in another ACCESS database sailor_123 Microsoft Access VBA Modules 1 8th May 2008 10:22 PM
Creating pivot table from Access database Cam Microsoft Excel Misc 1 19th Mar 2008 06:28 PM
Creating a Database Table within Access 2003/2007 Johnny E Jensen Microsoft C# .NET 1 21st Feb 2008 12:59 PM
Creating a table into another Access database =?Utf-8?B?YW5vbg==?= Microsoft Access 1 15th Nov 2007 07:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:43 PM.