473,385 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Creating table in Access database

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)
Nov 20 '05 #1
3 2382
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
Nov 20 '05 #2
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
Nov 20 '05 #3
On Fri, 9 Apr 2004 15:15:24 -0400, "Eric Carr" <es***********@ufl.nospam.edu> 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 ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Brian S. Smith | last post by:
Hi gang, Please help. I've been through the Access help, searched the Web, and I can't seem to get a straight answer. As the Subject line suggests, I want to run a fairly simple VB/Access Sub...
4
by: Tony | last post by:
G'day My attempt to create an MDE file was unsuccessful. The attempt produced an error that effectively said the (MDB) file was to big. The MDB consists of about 30 tables, 50 forms and 3...
7
by: John Baker | last post by:
Hi: I would like to know how to create a temp DB to store the data in a table while I do something else with the table. Specifically, how do I create the temp remove the temp I want to be...
1
by: Dixie | last post by:
I wish to add some fields to an existing table in code. I am using the following code from rkc. CurrentDb.Execute ("ALTER TABLE MyTable ADD MyNewField Text 25") This works , but I need to also set...
8
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;...
18
by: Ken Kazinski | last post by:
Does anyone know of a good example for creating a access database and then tables within that database. All the examples I have found so far use a SQL database. Thanks, Ken
4
by: RSH | last post by:
Hi, I have a situation where I have created a little application that makes an Access database from a SQL Database for reporting purposes. it does the job well, but it seems a bit slow. Is...
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
2
by: Andy | last post by:
Hi guys I having a problem creating a report in Access 2003 project talking to a SQL database through and ODBC connect. After hours of trying things from Access Help, MSDN and Google I still...
1
by: sainiamit25 | last post by:
Hi, I want to create a materlised view log in my database A and materlised view in some other database B. I was successful in creating materlised view in database B (after creating a dblink with...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.