
|
email this FAQ to a colleague
Q:
If I add a new record to my database, how do I keep track of where it gets inserted?
A:
When you add a new record, several factors determine where it will be inserted. If you need to come back to this record later, save a bookmark to the current row. However, when you insert records into a table without an index against Microsoft SQL Server, you will not be able to get back to the newly inserted row after you move the current record pointer unless a Requery is performed.
However, if you are using SQL Server and one column has a IDENTITY value you can execute the below script to get the IDENTITY of the row, if the column is also a primary key then you can use the returned value to access the row again.
'A little code to Give Out the Right Cookie
UserId=Request.Cookies("USER")
' If there isn't a cookie then Get One From the SQL Server
if UserId = "" then
Set connOnline = Server.CreateObject("ADODB.Connection")
connOnline.Open "UserDatabase", "login", "password"
sql="INSERT INTO tblUser DEFAULT VALUES SELECT @@IDENTITY 'UserId'"
Set RS = connOnline.Execute(sql)
NextRS=RS.NextRecordset
UserId=NextRS("UserId")
connOnline.Close
' Set Cookie
Response.Cookies("USER")=UserId
end if
Here is the SQL to create the Table in the UserDatabase
CREATE TABLE tblUser (UserId int IDENTITY NOT NULL PRIMARY KEY)
- Wayne Berry
|
Articles
|
|
Sep 15, 2005 - Building an Image Keyword System
|
|
|
Unlike text-based file formats image files aren't made up of words, which makes searching for an image file by keyword difficult. Instead of being able to simply open the file to see what it contains, we're stuck looking at the text around it and other metadata to determine the image's meaning. In this article, Ziran Sun shows you how to build a simple database-based image keyword system that allows you to associate keywords with images and use these keywords to make finding images easier.
[Read This Article] [Top]
|
|
|
|
|
|
Feb 10, 2005 - A Step-by-Step Guide To Using MySQL with ASP.NET - Part 1
|
|
|
Back in the days of classic ASP, if you were building a database-driven
web site, your choice was either to invest a lot of money to get a copy of Microsoft SQL Server
(or some other enterprise-ready database) or invest a lot of time finding a way to deal with the
performance and scalability limitations of Microsoft Access. Luckily these days there's
another viable alternative: MySQL.
[Read This Article] [Top]
|
|
|
|
|
|
|