Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
adding more than 1 record to dataset with an autoincrement field
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.adonet.


colin
I get an error whenever I attempt to add more than 1 new record to a dataset when the table has an autoincrement field as primary key. Is there something else i should be doing?

The dataset is using an autogenerated sqlinsert stored procedure, it works fine when adding only 1 record in an update

Colin

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
Smoke
If the SQL autoincrement number on the SQLdb is an "identity" field, you should "Refresh" or "Updated" each time you add a new record, so, the SQL will determine the number for that field and post on the column

maybe is that the prob u are having, try add a update comand between each record.

Hope it helps
<colin> wrote in message news:OyMIrRgzBHA.568@tkmsftngp07...
I get an error whenever I attempt to add more than 1 new record to a dataset when the table has an autoincrement field as primary key. Is there something else i should be doing?

The dataset is using an autogenerated sqlinsert stored procedure, it works fine when adding only 1 record in an update

Colin

Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
Colin Young
Are you setting the autoincrement to start at -1 and increment by -1? If not
you may have problems with the DB generated value colliding with values
generated by the DataSet.

Colin

<colin> wrote in message news:OyMIrRgzBHA.568@tkmsftngp07...
I get an error whenever I attempt to add more than 1 new record to a dataset
when the table has an autoincrement field as primary key. Is there something
else i should be doing?

The dataset is using an autogenerated sqlinsert stored procedure, it works
fine when adding only 1 record in an update

Colin

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
colin
Colin

Great thats exactly what I am looking for. Where do you set it

Colin

"Colin Young" <Click here to reveal e-mail address> wrote in message
news:uTJS$ZozBHA.568@tkmsftngp07...
> Are you setting the autoincrement to start at -1 and increment by -1? If
not
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
    
colin
I have set these autoincrement values in my dataset but the existing dataset
on my winform does not update!

if I view the schema I see the changes but Dataset properties still has the
original values.

If I generate a new dataset after setting the autoincrement the dataset
properties it shows the values as 0 an null in a readonly view how/where do
i set these autoincrement values for an existing Form

Colin

<colin> wrote in message news:eoXUYsP1BHA.1492@tkmsftngp03...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Open source windows
The Law Society’s guidelines on e-mail management
 
    
Arvind.R
Hi,

The AutoIncrementSeed and AutoIncrementStep properties of the column have
to be set to -1 and the AutoIncrement property must be set to true.

If the code were put in within a try-catch block, a clearer message could
be obtained. That should make it easier to debug.

Thanks.    

___________

This posting is provided "AS IS" with no warranties, and confers no rights.
___________

--------------------
Reply-To: <colin>
From: <colin>
Subject: adding more than 1 record to dataset with an autoincrement field
Date: Sun, 17 Mar 2002 22:53:51 -0000
Lines: 50
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="----=_NextPart_000_0020_01C1CE06.9B30B230"
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-ID: <OyMIrRgzBHA.568@tkmsftngp07>
Newsgroups:
microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.languages.v
b
NNTP-Posting-Host: pc1-dale3-0-cust115.not.cable.ntl.com 62.254.2.115
Path: cpmsftngxa07!tkmsftngp01!tkmsftngp07
Xref: cpmsftngxa07 microsoft.public.dotnet.languages.vb:35740
microsoft.public.dotnet.framework.adonet:14435
X-Tomcat-NG: microsoft.public.dotnet.framework.adonet

I get an error whenever I attempt to add more than 1 new record to a
dataset when the table has an autoincrement field as primary key. Is there
something else i should be doing?
The dataset is using an autogenerated sqlinsert stored procedure, it works
fine when adding only 1 record in an update
Colin

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
colin
thanks.

I could see what was happening without the debug steps, just did not now
about setting the step value different to the value at the DB

Colin

"Arvind.R" <Click here to reveal e-mail address> wrote in message
news:KaqacU4zBHA.1448@cpmsftngxa08...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Google Docs… no.
Twitter Elite
 
    
Eric Jonker
Well this is a nice one.
You can make this work as follows:

Suppose your dbtable is:

create table t (
id int identity primary key,
value varchar(20) not null
);

You may assign any value you like to a new row's ID column, I found that
increment and seed may both be 1. This works even if you have a key
contraint defined in your typed DataSet. The work is done in the DataAdapter
and the associated IDbCommands.

Here is how you configure your DataAdapter Commands
A) Don't make changes to or specify ID yourself, when talking to the
database:
- Configure your Insert command:
INSERT into t (value) values (@value);
SELECT id, value from t where id = @@identity;
/* if your DB doesn't support @@identity, enclose this command in a
transaction (if not already in an implicit one) and do SELECT max(id) newid
from t to obtain the same value @@identity does */
- Configure your Update command:
UPDATE t set value = @value where id = @Original_ID;
SELECT id, value from t where id = @Original_ID;
B) Make sure you update the TableMappings for the commands (including
Input/Output value).
C) Configure your DataAdapter's Insert (and Update) commands to use
Updatedrowsource=FirstReturnedRecord (preferably, but never
UpdateRowSource.None). This will ensure any value the database assigns to
fields will be assigned to fields in your DataSet.

This way, the ID value in your DataSet is always in-sync with your database
and you can add multiple rows. Eventually, when you still get errors, you
may try increment -1, seed -1 as well, but with MSDE, 1 resp 1 works fine
(even on already-populated data with minimum ID > 1 i.e. first inserted
record ever was deleted in the past).

Success,

Eric

<colin> wrote in message news:OyMIrRgzBHA.568@tkmsftngp07...
I get an error whenever I attempt to add more than 1 new record to a dataset
when the table has an autoincrement field as primary key. Is there something
else i should be doing?

The dataset is using an autogenerated sqlinsert stored procedure, it works
fine when adding only 1 record in an update

Colin

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
colin
Eric,

This was an old post I was surprised to see your welcome addition to it, (i
presume/hope it has not taken this long to find the answer)

[Original message clipped]

Makes you think that this should be default behavior especially for the
sqldatadapter doesnt it ?

incidentally using @@identity_scope will ensure you always get back the
correct ID after an insert

Colin

"Eric Jonker" <Click here to reveal e-mail address> wrote in message
news:eQQ0MeV4BHA.2348@tkmsftngp02...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
 
System.Data.Common.DataAdapter
System.Data.DataSet
System.Data.UpdateRowSource




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734