Solved

Use New Inserted Autonumber ID as session variable

Posted on 2012-03-27
1
396 Views
Last Modified: 2012-04-03
I am usually a PHP guy so I know basically nothing about .NET.  I am using an INSERT Record Behavior in Dreamweaver (I know I should be using VS but DW is easier for me to navigate).  I am using the basic insert record behavior and need to take that new IDENTITY line, store it in a session variable, and use it on the next page to insert it in another table with a FK so the tables relate.

I need code as again, I am new with .NET.  I have found some articles on the web in forums to create a stored procedure, etc. but I think that would be too complicated for what I need.  I have also been looking at Identity_Scope() but not sure I want to use that either.

So I need to create a new session variable with the new ID then use that ID on the next INSERT page and insert that ID into the database FK.  Thank you all!
0
Comment
Question by:palmtreeinfotech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 29

Accepted Solution

by:
sammySeltzer earned 500 total points
ID: 37796802
What's wrong with using SCOPE_IDENTITY()?

Assume this is your insert:

INSERT INTO [Products] ([ProductName], [CategoryID], [UnitPrice], [Discontinued]) VALUES (@ProductName, @CategoryID, @UnitPrice, @Discontinued)

'Grab the last inserted ID and assign it into a variable called @NewProductID

SELECT @NewProductID = SCOPE_IDENTITY()

Now, make it a session variable to be used in another page.

Session.Item("NewID") = @NewProductID

Then you should be able to use it on any page.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question