![]() |
|
|
Published: Monday, October 05, 1998 Sometimes when you insert a record into your SQL database using ASP, you want toget the identity value of the row you just inserted. Imagine, for example, thatyou allow a user to create a profile. When a user creates a new profile, a new rowis inserted into a table called CustomerProfile. Let's say CustomerProfile has thefollowing rows: an integer identity column / primary key named CustomerProfileID; a varchar(30) column named CustomerName; and a tinyint character field called CustomerAge. As soon as the user enters theirinformation and clicks "Save", you want them to be taken to the profile editing screen,where they will see the information they just entered and can edit the values andupdate their profile. Let's look at this as a series of three steps. First, the user must enter his or herinformation. Second, the database must be updated. Third, the user must be sent to theprofile editing page, and have their data shown. Step one could be a simple HTML pagewith a form in it, like so: In step 2, we need to insert a row into the table. Before I show you the code forStep 2, let's consider what information we need in Step 3. We will need to know theCustomerProfileID so that we can display the correct record. So, in Step 2 we need notonly insert the row, but grab the identity value of the row just inserted. Let's lookat the code for CreateProfile.asp: We make use of the system variable @@IDENTITY in SQL
to obtain the Identity column valuefor the row we just inserted. To find out more about SQL's system variables, check outthe SQL Books Online.For the final Step, we would just need an ASP page that would look very similar to theStep 1 HTML page, except it would have the values of the current Customer's profilealready entered into the I hope this article has helped! Happy Programming!
Related Articles:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||