Identity columns

T

tma

In my case, the column is defined as PK in Enterprise Manager. My issue is
adding a new row to a dataset which includes the PK/Auto increment column.
Without setting a value for that column, I get a Null error on the
column.add method. I'm going to get to reading your suggestion.



Ron Allen said:
tma,
Is the column defined as the primary key in Enterprise Manager? Just
having it as Autoincrement doesn't make it the primary key which may be
confusing the SqlClient modules. An autoincrement PK shouldn't be in an
insert statement at all as it should be generated by the database (and sent
back to the program for update). See the topic 'Retrieving Identity or
Autonumber Values' in the online help for a discussion on this. The ref isms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconretrievingi
dentityorautonumbervalues.htm
on my system.

Ron Allen

tma said:
I am ignorant as to how I can set properties of a column in a typed dataset.
Viewing the dataset in the designer reveals the following properties:

AutoIncrement = True
AutoIncrementSeed = [blank]
AutoIncrementStep=[blank]

ReadOnly=True
Type=int

I am creating a dataset based on the dataset I created from the data adapter
for the table.

I'm sorry I don't even know enough to adequately explain my problems...


Miha Markic said:
Hi,

Yes, but how the column is defined in the program?
Check out DataColumn.AutoIncrement* properties.
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

In Enterprise Manager, the column values are the following:

Identity = Yes
IdentitySeed = 100
IdentityIncrement = 1

The data type is Int = 4.


"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Is the column in datatable set as autoincrement?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Can someone help with how I might add a datarow to a dataset
where
the
Primary Key is an identity column and as such does not receive its
value
until the row is inserted into the db?

I get a null error adding the row to the dataset without a value in
the
PK
field.

Is this poor design or use of the identity field or is there a
technique
I
need to learn to accomplish this correctly?

Thanks.
 
W

William Ryan eMVP

TMA:

How did you add the PK and AutoIncrement? If you explicitly set both of
them on the DataTable (either in the designer if this is a strongly typed
dataset or through code if it isn't) then you should be fine. Can you post
the code you are using, that might help.

Actually, I just saw that there's code below: Here's a link that might help
http://www.knowdotnet.com/articles/adopartiii-printable.html Set the
AutoIncrementValue to 1 for instance (or actually -1 so that it will always
be a negative number and Access will assign that value, that way you won't
get any collissions.) Check out Bill Vaughn's Article...
www.betav.com ->articles -> MSDN - Managing an @@Identity Crisis. His
article deals with SQL Server Identity columns but the solution is virtually
identical in Access.

Thanks,

Bill

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
tma said:
In my case, the column is defined as PK in Enterprise Manager. My issue is
adding a new row to a dataset which includes the PK/Auto increment column.
Without setting a value for that column, I get a Null error on the
column.add method. I'm going to get to reading your suggestion.



Ron Allen said:
tma,
Is the column defined as the primary key in Enterprise Manager? Just
having it as Autoincrement doesn't make it the primary key which may be
confusing the SqlClient modules. An autoincrement PK shouldn't be in an
insert statement at all as it should be generated by the database (and sent
back to the program for update). See the topic 'Retrieving Identity or
Autonumber Values' in the online help for a discussion on this. The ref is
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconretrievingi
dentityorautonumbervalues.htm
on my system.

Ron Allen

tma said:
I am ignorant as to how I can set properties of a column in a typed dataset.
Viewing the dataset in the designer reveals the following properties:

AutoIncrement = True
AutoIncrementSeed = [blank]
AutoIncrementStep=[blank]

ReadOnly=True
Type=int

I am creating a dataset based on the dataset I created from the data adapter
for the table.

I'm sorry I don't even know enough to adequately explain my problems...


"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Hi,

Yes, but how the column is defined in the program?
Check out DataColumn.AutoIncrement* properties.
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

In Enterprise Manager, the column values are the following:

Identity = Yes
IdentitySeed = 100
IdentityIncrement = 1

The data type is Int = 4.


"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Is the column in datatable set as autoincrement?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Can someone help with how I might add a datarow to a dataset where
the
Primary Key is an identity column and as such does not receive its
value
until the row is inserted into the db?

I get a null error adding the row to the dataset without a
value
in
the
PK
field.

Is this poor design or use of the identity field or is there a
technique
I
need to learn to accomplish this correctly?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top