Recommended: Asp tutorial on how to create 2-column pagination display code Display format: ID NAME | ID NAME 1 JULIET | 2 PALYBOY 3 BABY |4 TOM 5 LENA | 6 JERY Number of pages before and after pages: 1/4 6 items/Total number of records on pages: 25 codes: !- -#include file=conn.asp-- html body bgcolor=#FFFFF text=#000000 table width=60% border=1
1.SQL Server
For SQL Server 2000, it provides two brand new functions (IDENT_CURRENT, SCOPE_IDENTITY) and improves the shortcomings of @@IDENTITY. When you insert a new record, you can call the function:
PRINT IDENT_CURRENT('table') 'This will get the new IDENTITY value regardless of whether there are records added in the database (this avoids the connection limit of @@IDENTITY)
Or: PRINT SCOPE_IDENTITY() 'This will get the IDENTITY value of the latest record created by other programs such as the current stored procedure, trigger, etc.
There is a problem with the global variable @@IDENTITY. When performing insert on a table, if the trigger program performs an insert operation, then inserts the record in another table, so that the return of the @@IDENTITY value is the second IDENTITY value of the table.
In ASP you can do this:
<%
set conn = Server.CreateObject(ADODB.Connection)
conn.open <conn string>
set rs = conn.execute(exec myProc @param1= & fakeValue)
response.write New ID was & rs(0)
rs.close: set rs = nothing
conn.close: set conn = nothing
%>
2.Access
For Access, you can use the following method:
<%
set conn = Server.CreateObject(ADODB.Connection)
conn.open <conn string>
conn.execute Insert into someTable(intField) values( & fakeValue & )
set rs = conn.execute(select MAX(ID) from someTable)
response.write New ID was & rs(0)
rs.close: set rs = nothing
conn.close: set conn = nothing
%>
However, for multiple people to add data to the database at the same time, we need to use the adOpenKeyset cursor of the record set to prevent errors. For example, the following example:
<%
set conn = Server.CreateObject(ADODB.Connection)
conn.open <conn string>
set rs = Server.CreateObject(ADODB.Recordset)
rs.open select [intField] from someTable where 1=0, conn, 1, 3
rs.AddNew
rs(intField) = fakeValue
rs.update
response.write New ID was & rs(id)
rs.close: set rs = nothing
conn.close: set conn = nothing
%>
Share: Methods for parsing various types of data files in ASP 1. Create an MdbRecordset object. An MDB database is a complete database that may contain several data tables. In this function, the function of Connection is to connect to the database, and the function of Recordset is to open the data table. Function CreateMdbRecordset (database file name, data table name or select statement) Dim conn,Provider,DBPat