OK, here's what I'm doing. I have a SQL Server 2005 table with an auto-number Identity column that I will be inserting to. I used the DataSet designer to add a table adapter to my DataSet to which I want to add an insert command.
Now, I want to know if there is some way to retrieve the number that was inserted into the Identity field. I know that if I were writing the update command manually I could set a parameter to SCOPE_IDENTITY(), but is there anyway to do this in the TableAdapter's insert query that I will be adding?
Thanks.
6 5562
I personally have avoided this situation precisely because it is so unintuitive, but the situation is obviously legitimate..
Just to help get you started...this is outdated (2003), but the keywords should lead you in the right direction: Bill Vaughn - IdentityValues
Here is the MSDN blurb. Again, not intutive. Seems the assumption is your insert will be done via a stored procedure. Is that an option for you? That is, can your Adapter's Insert query call a stored procedure? Retrieving Identity Or AutoNumber Values
Thanks for the repy.
To answer your question, yes, an SP is an option. Actually, it was the plan.
I'll take a look at both of these tomorrow and give them a shot.
I'll be sure to post the results.
Thanks!
Plater 7,872
Recognized Expert Expert
Wouldn't the number of rows change? Could you just look at the last row in the index?
Thanks a lot, mldisibio.
Turns out that the output params were a real hassle when you are using the dataset to do the hard work for you. I figured out that I can make an SP with the insert statement followed by a select statement, and get exactly the result I want. - CREATE PROCEDURE name
-
--paramlist here
-
AS
-
BEGIN
-
--insert statement here
-
SELECT SCOPE_IDENTITY() AS IdOfNewRow
-
END
And then you add a new query to your table adapter, specifying to use an existing SP. VS will poll the DB and find your SP, find it's input parameters, and it's output values, and let you specify it as a single return value or a rowset return value. I chose single value.
It works perfectly.
Again, thanks for your help.
Plater 7,872
Recognized Expert Expert
Hehe, when you said you couldn't use scope_indentity() above, I just wrote that off.
I use just:
return SCOPE_IDENTITY()
But I guess if you use SELECT it would come out like a "table"
Hehe, when you said you couldn't use scope_indentity() above, I just wrote that off.
I use just:
return SCOPE_IDENTITY()
But I guess if you use SELECT it would come out like a "table"
Well, if I would have thought of RETURN instead of SELECT I would have used that. Oh well. all's well that ends well.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: (Pete Cresswell) |
last post by:
This doesn't work because the first INSERT is creating multiple
records for multiple projects. @@IDENTITY, then, contains the Identity
column value for the last tblWeekReportedLine record...
|
by: Jason L James |
last post by:
Hi all,
I recently wrote a vb.net app using oledb to
an access database. When I inserted new
rows in my datatable the identity column
was automatically created. This app used
an un-typed...
|
by: pb648174 |
last post by:
In a multi-user environment, I would like to get a list of Ids
generated, similar to:
declare @LastId int
select @LastId = Max(Id) From TableMania
INSERT INTO TableMania (ColumnA, ColumnB)...
|
by: Rico |
last post by:
Hello,
I am in the midst of converting an Access back end to SQL Server Express.
The front end program (converted to Access 2003) uses DAO throughout. In
Access, when I use recordset.AddNew I...
|
by: Brad Eck |
last post by:
In Access, newID returns a unique for the table. In SQL Server, newid()
returns a GUID - unique in the world. I do not need or desire that
complexity. Is there a way to get a simple unique int on...
| |
by: Susanne Klemm |
last post by:
Hello!
I use a procedure to insert a new row into a table with an identity
column. The procedure has an output parameter which gives me the
inserted identity value. This worked well for a long...
|
by: Veeru71 |
last post by:
Given a table with an identity column (GENERATED BY DEFAULT AS
IDENTITY),
is there any way to get the last generated value by DB2 for the
identity column?
I can't use identity_val_local() as...
|
by: gunnar.sigurjonsson |
last post by:
I´m having some problem retrieving identity value from my newly
inserted row into a view.
I have two tables T1 and T2 which I define as following
CREATE TABLE T1
(
id BIGINT GENERATED ALWAYS...
|
by: sajithamol |
last post by:
I have a table with an Identity column. The latest Identity value is 1298. A row with Identity 324 was deleted by mistake and I need to insert it now. But if I insert it now it will have Identity...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |