Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LAST_INSERT_ID prob...

Status
Not open for further replies.

mjonson

Technical User
Mar 9, 2004
128
GB
Hi,

I have an ASP page that is posting to a mysql db.
I want to get the Auto Increment 'cusID' of the last record and put it in a URL string.

ne tips ideas

ASP so far

Set rs2 = Server.CreateObject("ADODB.Recordset")
autoidsql = "SELECT LAST_INSERT_ID() FROM tbl_customers"
rs2.Open autoidsql, conn
tmpid = rs2
Response.Redirect("custviewdeal.asp?key=" & Server.URLEncode(tmpid))
 
i get the error

Type mismatch: 'Server.URLEncode'
/dfasp/custadddeal.asp, line 145
 
I would assume Server.URLEncode() expects a string. Is tmpid a string?

In any regard, tmpid will be, if not an integer, an integer-numeric string. There won't be anything in that string that will require urlencoding.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
am trying to write the results of rs2
but get error

Response object, ASP 0185 (0x8002000E)
A default property was not found for the object.
/dfasp/custadddeal.asp

code looks like

Set rs2 = Server.CreateObject("ADODB.Recordset")
autoidsql = "SELECT LAST_INSERT_ID() FROM tbl_customers"
rs2.Open autoidsql, conn
key = rs2
response.write (key)
 
I see what you're doing in both places.

tmpid and key will both be objects, not strings that can be output.

There should be some object method or something to retrieve a particular value from an object to a string. However, what that method would be is a VBScript question, not a MySQL question.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Ok,

to get the recently posted recs id i used

Set rs = Server.CreateObject("ADODB.Recordset")
autoidsql = "SELECT cusID FROM tbl_customers WHERE cusID = last_insert_id()"
rs.Open autoidsql, conn
key = rs(0)

it was (0) that stumped me!

thanks for yur help sleipnir214
 
Assuming tmpId is of type LONG ( INT(11) in MySQL Speak )


Try this

rs2.Open "SELECT LAST_INSERT_ID() As NewId ", conn
tmpid = rs2!NewId
Response.Redirect("custviewdeal.asp?key=" & Server.URLEncode(tmpid))


OR

You can forget tmpid completely using

rs2.Open "SELECT LAST_INSERT_ID() As NewId ", conn

Response.Redirect("custviewdeal.asp?key=" & Server.URLEncode(rs2!NewId))




'ope-that-'elps.



G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top