Hi,

I have a datatable with 1 row. It consists of columns: name,
date, time and value. I use dataadapter to insert these data
to a SQL2000 table. Structure of the table is almost the
same. It contains all these 4 columns plus one more which
is a table PrimaryKey and IdentityColumn -
autoincrementing integer.
After SqlDataAdapter.Update I would like to get that value of
PrimaryKey assigned by sql2000 to my new row in sql table.
How can I do it ?

Thank in advance!

Przemo

Re: Getting ID from SQL after inserting by Dotnetified

Dotnetified
Tue Jul 29 10:36:50 CDT 2003

Let's assume this:

Table Customer:
CustomerId int Identity Not Null
FirstName varchar(100)
LastName varchar(100)
FavoriteColor varchar(100)

----

Your Dataadapter InsertCommand text should look something like this:

INSERT INTO Customer (FirstName, LastName, FavoriteColor) VALUES
(@FirstName, @LastName, @FavoriteColor); SELECT * FROM Customer WHERE
CustomerId = @@IDENTITY

After you perform your update, you should be able to retrieve the new ID
from the datarow that you added. Hope this helps . . .

Mike Joseph
Hypersite.net

"Przemo" <p.dutkiewicz@deltatrans.pl> wrote in message
news:06fa01c355ad$2498c240$a601280a@phx.gbl...
> Hi,
>
> I have a datatable with 1 row. It consists of columns: name,
> date, time and value. I use dataadapter to insert these data
> to a SQL2000 table. Structure of the table is almost the
> same. It contains all these 4 columns plus one more which
> is a table PrimaryKey and IdentityColumn -
> autoincrementing integer.
> After SqlDataAdapter.Update I would like to get that value of
> PrimaryKey assigned by sql2000 to my new row in sql table.
> How can I do it ?
>
> Thank in advance!
>
> Przemo



Re: Getting ID from SQL after inserting by David

David
Thu Aug 07 12:23:57 CDT 2003

I was looking to do basically the same thing.

The only difference would be
1) DataTable with MANY rows of data
2) Using DataAdapter pointing to a Stored Proc

To carry the previous example forward, would this be sufficient to allow
the DataTable to be updated with the primary key that could be checked
after returning from the insert???

Thanks,
Dave
DavidElliott@BellSouth.net

=================================================
CREATE PROCEDURE up_Customer_add

@FirstName varchar(100),
@LastName varchar(100),
@Color varchar(100),
@CustomerID int Output

AS

insert into Customer(FirstName, LastName, FavoriteColor)
values (@FirstName, @LastName, @FavoriteColor)

set @CustomerID = @@IDENTITY
GO
=================================================

On Tue, 29 Jul 2003 11:36:50 -0400, "Dotnetified" <mikej@hypersite.net> wrote:

>Let's assume this:
>
>Table Customer:
>CustomerId int Identity Not Null
>FirstName varchar(100)
>LastName varchar(100)
>FavoriteColor varchar(100)
>
>----
>
>Your Dataadapter InsertCommand text should look something like this:
>
>INSERT INTO Customer (FirstName, LastName, FavoriteColor) VALUES
>(@FirstName, @LastName, @FavoriteColor); SELECT * FROM Customer WHERE
>CustomerId = @@IDENTITY
>
>After you perform your update, you should be able to retrieve the new ID
>from the datarow that you added. Hope this helps . . .
>
>Mike Joseph
>Hypersite.net
>
>"Przemo" <p.dutkiewicz@deltatrans.pl> wrote in message
>news:06fa01c355ad$2498c240$a601280a@phx.gbl...
>> Hi,
>>
>> I have a datatable with 1 row. It consists of columns: name,
>> date, time and value. I use dataadapter to insert these data
>> to a SQL2000 table. Structure of the table is almost the
>> same. It contains all these 4 columns plus one more which
>> is a table PrimaryKey and IdentityColumn -
>> autoincrementing integer.
>> After SqlDataAdapter.Update I would like to get that value of
>> PrimaryKey assigned by sql2000 to my new row in sql table.
>> How can I do it ?
>>
>> Thank in advance!
>>
>> Przemo
>