setting a value for the primary key

C

Ced

Hi,

I'm using a strong typed dataset to add new records to a table but I don't
use the Fill method before because I don't want to load all these records in
memory (I only want to add some new ones) so I can't use the code below to
give a value for the primary key: dr.PRO_NUM = ds.Tables["PRO"].Rows.Count +
1;

I tried to set the primary key's field to "AutoIncrement" in the schema but
the "NewRow()" method returns "0" as value for the same reason.

Do you know any easy way to do that ?

Thanks,
Ced
 
G

Gavin Joyce

Hi,

Are your primary key colums identity columns? If not, change the column to
identity and SQL will look after asigning the record unique IDs.

Thanks,
Gavin Joyce
www.gavinjoyce.com

--
___________________________________________________________
nTierGen.NET Code Generator - http://www.nTierGen.NET/

Stored Procedures (Get, GetPaged, Insert, Update, Delete)
Data Access Layer - C#
Business Rules Layer - C# & VB.NET
Strongly-Typed DataSets - C#
Web Services - C#
___________________________________________________________
Ced said:
It is not a problem of "starting value". The problem is that I there are
already rows with the PK 0 and 1 in the database...ok ?

Ced

Al Cadalzo said:
What did you set the AutoIncrementSeed to? If you did not specify then the
first row would get value = 0, The next row you add would get a value
of
1.

Al

records
below
to
give a value for the primary key: dr.PRO_NUM =
ds.Tables["PRO"].Rows.Count
+
1;

I tried to set the primary key's field to "AutoIncrement" in the
schema
but
the "NewRow()" method returns "0" as value for the same reason.

Do you know any easy way to do that ?

Thanks,
Ced
 
A

Al Cadalzo

Then how about a starting value of -1 and an increment of -1?

Ced said:
It is not a problem of "starting value". The problem is that I there are
already rows with the PK 0 and 1 in the database...ok ?

Ced

Al Cadalzo said:
What did you set the AutoIncrementSeed to? If you did not specify then the
first row would get value = 0, The next row you add would get a value
of
1.

Al

records
below
to
give a value for the primary key: dr.PRO_NUM =
ds.Tables["PRO"].Rows.Count
+
1;

I tried to set the primary key's field to "AutoIncrement" in the
schema
but
the "NewRow()" method returns "0" as value for the same reason.

Do you know any easy way to do that ?

Thanks,
Ced
 
C

Ced

No...We are not on the same way. The user can add records more than one time
so if I don't use the Fill method.the only way I see is to use a SqlCommand
with select statement and ExecuteNonQuery.

Al Cadalzo said:
Then how about a starting value of -1 and an increment of -1?

Ced said:
It is not a problem of "starting value". The problem is that I there are
already rows with the PK 0 and 1 in the database...ok ?

Ced

Al Cadalzo said:
What did you set the AutoIncrementSeed to? If you did not specify
then
the
first row would get value = 0, The next row you add would get a value
of
1.

Al

Hi,

I'm using a strong typed dataset to add new records to a table but I don't
use the Fill method before because I don't want to load all these records
in
memory (I only want to add some new ones) so I can't use the code
below
to
give a value for the primary key: dr.PRO_NUM = ds.Tables["PRO"].Rows.Count
+
1;

I tried to set the primary key's field to "AutoIncrement" in the schema
but
the "NewRow()" method returns "0" as value for the same reason.

Do you know any easy way to do that ?

Thanks,
Ced
 
C

Ced

Hi Gavin,

sorry but what are identity columns ?
How can I change that ?

thanks,
Ced

Gavin Joyce said:
Hi,

Are your primary key colums identity columns? If not, change the column to
identity and SQL will look after asigning the record unique IDs.

Thanks,
Gavin Joyce
www.gavinjoyce.com

--
___________________________________________________________
nTierGen.NET Code Generator - http://www.nTierGen.NET/

Stored Procedures (Get, GetPaged, Insert, Update, Delete)
Data Access Layer - C#
Business Rules Layer - C# & VB.NET
Strongly-Typed DataSets - C#
Web Services - C#
___________________________________________________________
Ced said:
It is not a problem of "starting value". The problem is that I there are
already rows with the PK 0 and 1 in the database...ok ?

Ced

Al Cadalzo said:
What did you set the AutoIncrementSeed to? If you did not specify
then
the
first row would get value = 0, The next row you add would get a value
of
1.

Al

Hi,

I'm using a strong typed dataset to add new records to a table but I don't
use the Fill method before because I don't want to load all these records
in
memory (I only want to add some new ones) so I can't use the code
below
to
give a value for the primary key: dr.PRO_NUM = ds.Tables["PRO"].Rows.Count
+
1;

I tried to set the primary key's field to "AutoIncrement" in the schema
but
the "NewRow()" method returns "0" as value for the same reason.

Do you know any easy way to do that ?

Thanks,
Ced
 

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