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