Solved

Use New Inserted Autonumber ID as session variable

Posted on 2012-03-27
1
387 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
1 Comment
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 500 total points
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now