Hej! Jag använder följande kod för att lägga in en ny användare i databasen (MS ACCESS). Vad jag vill är att ge användaren recordID direkt. direkt efter .execute kan du skriva en sats som hämtar upp recordid:Ge nyregistrerad användare recordID direkt
Hoppas någon har en lösning, för jag har provat men inte lyckats.
/Bosse
<table align=center width=100%>
<tr><TD>
<BR>
<%
Sub AddUserInformation
Dim SQLDataInsertionString
Dim CommandObject
' Create an instance of the Command object.
Set CommandObject= Server.CreateObject("ADODB.Command")
' The ActiveConnection property is used to connect the Command Object
' to the Connection Object.
Set CommandObject.ActiveConnection = DatabaseConnection
' The SQL string that inserts the tblUsers data about the user is created.
SQLDataInsertionString = "INSERT INTO tblUsers (Password, Kategori, Adress, PostNummer, PostAdress," & _
"Datum, Email, Tel, Namn," & _
"Fax) VALUES (?,?,?,?,?,?," & _
"?,?,?,?)"
' The SQL statement that actually inserts the data is defined
CommandObject.CommandText = SQLDataInsertionString
' The prepared or pre-compiled SQL statement defined in the
' CommandText property is saved.
CommandObject.Prepared = True
' The parameters of the SQL string are defined below.
CommandObject.Parameters.Append _
CommandObject.CreateParameter("Password",200, ,255 )
CommandObject.Parameters.Append _
CommandObject.CreateParameter("Kategori",200, ,255 )
CommandObject.Parameters.Append _
CommandObject.CreateParameter("Adress",200, ,255 )
CommandObject.Parameters.Append _
CommandObject.CreateParameter("PostNummer",200, ,255 )
CommandObject.Parameters.Append _
CommandObject.CreateParameter("PostAdress",200, ,255 )
CommandObject.Parameters.Append _
CommandObject.CreateParameter("Datum",200, ,255 )
CommandObject.Parameters.Append _
CommandObject.CreateParameter("Email",200, ,255 )
CommandObject.Parameters.Append _
CommandObject.CreateParameter("Tel",200, ,255 )
CommandObject.Parameters.Append _
CommandObject.CreateParameter("Namn",200, ,255 )
CommandObject.Parameters.Append _
CommandObject.CreateParameter("Fax",200, ,255 )
' Information entered by the user is added to the Guest Book database
CommandObject("Password") = Request.Form.Item("Password")
CommandObject("Kategori") = Request.Form.Item("Kategori")
CommandObject("Adress") = Request.Form.Item("Adress")
CommandObject("PostNummer") = Request.Form.Item("PostNummer")
CommandObject("PostAdress") = Request.Form.Item("PostAdress")
CommandObject("Datum") = Date
CommandObject("Email") = Request.Form.Item("Email")
CommandObject("Tel") = Request.Form.Item("Tel")
CommandObject("Namn") = Request.Form.Item("Namn")
CommandObject("Fax") = Request.Form.Item("Fax")
CommandObject.Execute
End Sub
' ########## End Subroutine ##########
If Request.Form.Count <= 0 Then
Response.Write ("I am sorry but you did not fill in the Form.")
Else
' Create an instance of the Connection Object
Set DatabaseConnection = Server.CreateObject("ADODB.Connection")
' Open a connection to the Guest Book File DSN
' Before the following statement can execute properly, you have to
' create a File DSN for the Guest Book database as outlined in the
' book.
DatabaseConnection.Open "hemsidor"
Call AddUserInformation
DatabaseConnection.Close
Response.Write ("<FONT FACE=Arial,Helvetica SIZE=2>Tack, "&Request.Form.Item("Namn")&"! ")
Response.Write ("Du är nu registrerad!<BR><BR>Anteckna AnvändarID: <U>"&Request.Form.Item("Password")&"</U> och angivet telefonnummer <U>"&Request.Form.Item("Tel")&"</U>, vilket kommer att behövas när du ska logga in!<BR></FONT>")
End If
%>
<BR>Jag vill
[Logga in]
<br>
</TD>
</TD>
</TABLE>Sv: Ge nyregistrerad användare recordID direkt
set con=server.createobject("adodb.connection")
con.open DatabaseConnection
set rst=con.execute("select top 1 recordid from user order by datum desc")
if not rst.eof then
recordid = rst(0)
end if
set rst = nothing
Bäst vore kanske att köra .refresh på commandobjektet och hämta upp det värdet som precis skrevs om det nu går...