Primary Key as Identity column

T

tma

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.
 
T

tma

In Enterprise Manager, the column values are the following:

Identity = Yes
IdentitySeed = 100
IdentityIncrement = 1

The data type is Int = 4.


Miha Markic said:
Is the column in datatable set as autoincrement?

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

tma said:
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.
 
M

Miha Markic [MVP C#]

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

tma said:
In Enterprise Manager, the column values are the following:

Identity = Yes
IdentitySeed = 100
IdentityIncrement = 1

The data type is Int = 4.


Miha Markic said:
Is the column in datatable set as autoincrement?

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

tma said:
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
technique
 
T

tma

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

tma said:
In Enterprise Manager, the column values are the following:

Identity = Yes
IdentitySeed = 100
IdentityIncrement = 1

The data type is Int = 4.


Miha Markic said:
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.
 
R

Ron Allen

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 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

tma said:
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.
 
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.
 
R

Ron Allen

tma,
You will want to set AutoIncrementSeed and AutoIncrementStep to -1 for
your column so that generated values don't collide with items other
processes might be inserting. Then retrieve the actual value. I'd
recommend a copy of 'ADO.NET Core Reference' by David Sceppa which has many
examples and good discussions of Autoincrement keys.

Ron Allen

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.
 
M

Miha Markic [MVP C#]

Hi tma,

Yes, as Ron suggested try setting Seed and Step to certain values, -1 and -1
are normally the best choice.

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

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