|
 |
asp_databases thread: Retrieving AutoNumber after AddNew
Message #1 by "Grant I" <giswim1@a...> on Mon, 25 Jun 2001 22:37:06
|
|
Ok I looked at the page you guys recommended about retrieving the
Autonumber after you add a new record to the database. It still doesn't
work. Could you guys take a look at this? I'm sorry for so many posts,
but no one else around here knows much ASP. Thanks again!!
-----------
>-My Code-<
-----------<!--#include file="adovbs.inc"-->
<%
' Declare variables and open a connection to the database
Dim objConn, objRS, strOut
Dim ConnectionString, strCN
Dim strPH, descrip
Set objConn = Server.CreateObject("ADODB.Connection")
'strConnection = "Data Source=rd_issues;"
'strConnection = strConnection & "User ID=admin;Password=;"
ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);"
ConnectionString = ConnectionString & "DBQ=" & Server.MapPath
("rd_issues.mdb")
objConn.Open ConnectionString
set objRS= Server.CreateObject ("ADODB.Recordset")
'set objRS.ActiveConnection = objConn
if Request.Form("bugrep") <> "" then
' Set up record set to be used
dim cat, stat,prio, comp, type1, work, repby, bugid
objRS.CursorLocation = adUseServer
objRS.CursorType = adOpenDynamic
objRS.LockType = adLockOptimistic
objRS.Open "rd_issues", objConn, , , adCmdTable
' Add data to current record set
objRS.AddNew
descrip = Trim(Request.Form("bugrep"))
objRS("Description") = descrip
objRS("Date_Reported") = Request.Form("date")
cat = Request.Form("category")
objRS("Category") = cat
stat = Request.Form("status")
objRS("Status") = stat
prio = Request.Form("priority")
objRS("Priority") = prio
comp = Request.Form("CompDate")
objRS("CompDate") = comp
work = Request.Form("PersonWorking")
objRS("PersonWorking") = work
type1 = Request.Form("type")
objRS("Type") = type1
repby = Request.Form("Reported_By")
objRS("Reported_By") = repby
' Update record set and database, and report bug ID
objRS.Update
bugid = objRS.Fields.Item(0).Value
objRS.Close
objConn.Close
set objRS = nothing
set objConn = nothing
Response.Write ("Your issue has been reported. The corresponding
ID number is ")
Response.Write (bugid)
Response.Write (". <BR><BR>")
%>
<a href="index.asp"> Return to the Research Desktop main page </a>
<%
else
%>
<script LANGUAGE="JavaScript">
alert("Please enter a description of the problem you are
experiencing")
history.back()
</script>
<%
end if
%>
Message #2 by "Ken Schaefer" <ken@a...> on Tue, 26 Jun 2001 11:30:03 +1000
|
|
Use the OLEDB Provider, not the ODBC Driver...
http://www.adopenstatic.com/experiments/fastestautonumber.asp
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: "Grant I" <giswim1@a...>
To: "ASP Databases" <asp_databases@p...>
Sent: Monday, June 25, 2001 10:37 PM
Subject: [asp_databases] Retrieving AutoNumber after AddNew
: Ok I looked at the page you guys recommended about retrieving the
: Autonumber after you add a new record to the database. It still doesn't
: work. Could you guys take a look at this? I'm sorry for so many posts,
: but no one else around here knows much ASP. Thanks again!!
:
: -----------
: >-My Code-<
: -----------<!--#include file="adovbs.inc"-->
: <%
: ' Declare variables and open a connection to the database
: Dim objConn, objRS, strOut
: Dim ConnectionString, strCN
: Dim strPH, descrip
:
: Set objConn = Server.CreateObject("ADODB.Connection")
: 'strConnection = "Data Source=rd_issues;"
: 'strConnection = strConnection & "User ID=admin;Password=;"
:
: ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);"
: ConnectionString = ConnectionString & "DBQ=" & Server.MapPath
: ("rd_issues.mdb")
: objConn.Open ConnectionString
:
: set objRS= Server.CreateObject ("ADODB.Recordset")
: 'set objRS.ActiveConnection = objConn
:
: if Request.Form("bugrep") <> "" then
: ' Set up record set to be used
: dim cat, stat,prio, comp, type1, work, repby, bugid
: objRS.CursorLocation = adUseServer
: objRS.CursorType = adOpenDynamic
: objRS.LockType = adLockOptimistic
: objRS.Open "rd_issues", objConn, , , adCmdTable
:
: ' Add data to current record set
: objRS.AddNew
: descrip = Trim(Request.Form("bugrep"))
: objRS("Description") = descrip
: objRS("Date_Reported") = Request.Form("date")
: cat = Request.Form("category")
: objRS("Category") = cat
: stat = Request.Form("status")
: objRS("Status") = stat
: prio = Request.Form("priority")
: objRS("Priority") = prio
: comp = Request.Form("CompDate")
: objRS("CompDate") = comp
: work = Request.Form("PersonWorking")
: objRS("PersonWorking") = work
: type1 = Request.Form("type")
: objRS("Type") = type1
: repby = Request.Form("Reported_By")
: objRS("Reported_By") = repby
: ' Update record set and database, and report bug ID
: objRS.Update
:
: bugid = objRS.Fields.Item(0).Value
: objRS.Close
: objConn.Close
: set objRS = nothing
: set objConn = nothing
: Response.Write ("Your issue has been reported. The corresponding
: ID number is ")
: Response.Write (bugid)
: Response.Write (". <BR><BR>")
:
: %>
: <a href="index.asp"> Return to the Research Desktop main page </a>
: <%
:
: else
: %>
: <script LANGUAGE="JavaScript">
: alert("Please enter a description of the problem you are
: experiencing")
: history.back()
: </script>
: <%
: end if
: %>
Message #3 by "G.Vijay Kumar" <happygv@y...> on Tue, 26 Jun 2001 08:14:49
|
|
Hi,
Pls copy and paste the following lines after you close the recordset
object and before you close the connection object.
'----------------
objRS.Open "<TABLENAME>", Conn, , , adCmdTable
objRS.MoveLast
bugid=objRS.Fields.Item(0).Value
objRS.Close
'---------------
This works fine. All the best.
Regards
Vijay.G
> Ok I looked at the page you guys recommended about retrieving the
> Autonumber after you add a new record to the database. It still doesn't
> work. Could you guys take a look at this? I'm sorry for so many posts,
> but no one else around here knows much ASP. Thanks again!!
>
> -----------
> >-My Code-<
> -----------<!--#include file="adovbs.inc"-->
> <%
> ' Declare variables and open a connection to the database
> Dim objConn, objRS, strOut
> Dim ConnectionString, strCN
> Dim strPH, descrip
>
> Set objConn = Server.CreateObject("ADODB.Connection")
> 'strConnection = "Data Source=rd_issues;"
> 'strConnection = strConnection & "User ID=admin;Password=;"
>
> ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);"
> ConnectionString = ConnectionString & "DBQ=" & Server.MapPath
> ("rd_issues.mdb")
> objConn.Open ConnectionString
>
> set objRS= Server.CreateObject ("ADODB.Recordset")
> 'set objRS.ActiveConnection = objConn
>
> if Request.Form("bugrep") <> "" then
> ' Set up record set to be used
> dim cat, stat,prio, comp, type1, work, repby, bugid
> objRS.CursorLocation = adUseServer
> objRS.CursorType = adOpenDynamic
> objRS.LockType = adLockOptimistic
> objRS.Open "rd_issues", objConn, , , adCmdTable
>
> ' Add data to current record set
> objRS.AddNew
> descrip = Trim(Request.Form("bugrep"))
> objRS("Description") = descrip
> objRS("Date_Reported") = Request.Form("date")
> cat = Request.Form("category")
> objRS("Category") = cat
> stat = Request.Form("status")
> objRS("Status") = stat
> prio = Request.Form("priority")
> objRS("Priority") = prio
> comp = Request.Form("CompDate")
> objRS("CompDate") = comp
> work = Request.Form("PersonWorking")
> objRS("PersonWorking") = work
> type1 = Request.Form("type")
> objRS("Type") = type1
> repby = Request.Form("Reported_By")
> objRS("Reported_By") = repby
> ' Update record set and database, and report bug ID
> objRS.Update
>
> bugid = objRS.Fields.Item(0).Value
> objRS.Close
> objConn.Close
> set objRS = nothing
> set objConn = nothing
> Response.Write ("Your issue has been reported. The corresponding
> ID number is ")
> Response.Write (bugid)
> Response.Write (". <BR><BR>")
>
> %>
> <a href="index.asp"> Return to the Research Desktop main page </a>
> <%
>
> else
> %>
> <script LANGUAGE="JavaScript">
> alert("Please enter a description of the problem you are
> experiencing")
> history.back()
> </script>
> <%
> end if
> %>
>
>
>
>
|
|
 |