Advertisement

09.19.2007 at 03:36PM PDT, ID: 22840092
[x]
Attachment Details

VS2005 TableAdapter return values from Insert() - not current record

Asked by Zernk in Visual Studio

Tags: , , ,

Hello Experts  (1st post at EE),

I'm using a TableAdapter in VS2005 with SQL2000.  I need to get the identity value of the record I just inserted, and using the two methods I found through web searches both fail:

The auto-generated query always returns the first record in the table, even though in the TableAdapter Confguration, Advanced Options, "Refresh the DataTable" is checked.  Here is the autogenerated query:

INSERT INTO [dbo].[SISession] ([IX_SICourse], [IX_SILeader], [SessionDateTime]) VALUES (@IX_SICourse, @IX_SILeader, @SessionDateTime);
SELECT IX_SISession, IX_SICourse, IX_SILeader, SessionDateTime FROM dbo.SISession WHERE (IX_SISession = SCOPE_IDENTITY())


The second method I tried was to alter the query to select just SCOPE_IDENTITY().  In the query's properties, I changed the Execute Mode of the query to "Scalar".  It always returns 1.  Here is that query:

INSERT INTO [dbo].[SISession] ([IX_SICourse], [IX_SILeader], [SessionDateTime]) VALUES (@IX_SICourse, @IX_SILeader, @SessionDateTime);
SELECT SCOPE_IDENTITY()

I've created a new project with nothing but what is required for this operation, and still get the same results.

Any ideas?Start Free Trial
[+][-]09.20.2007 at 01:24AM PDT, ID: 19926817

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Visual Studio
Tags: tableadapter, insert, return, value
Sign Up Now!
Solution Provided By: nogovoia
Participating Experts: 1
Solution Grade: B
 
 
[+][-]09.20.2007 at 07:13AM PDT, ID: 19928454

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.20.2007 at 10:39AM PDT, ID: 19930038

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_1_20070628