ASP max id

I'd like to insert the data to my table, however I want to know which row I enter the data.
I mean I want to know the id of my last data entry.
how can I do that?
thank you in advance.

sqlcumle = "insert into tablename(Ad,Tel,Eposta,Sehir,Mark,Konu,Adres,Promosyon)  values('" & ad & "','" & tel & "','" & email & "','" & sehir & "','" & mark& "','" & konu & "','" & adres & "','" & promosyon & "')"
rs.open sqlcumle, con, 1, 3	
 
sqlcumle2= "Select MAX(id) FROM tablename"
con.execute sqlcumle2
id2=rs(id)

Open in new window

LVL 1
BRMarketingAsked:
Who is Participating?
 
Ryan ChongConnect With a Mentor Commented:
emm, try:

sqlcumle2= "Select MAX(id) as maxid FROM tablename"
set rs = con.execute(sqlcumle2)
if rs.eof = false then
   id2=rs("maxid")
end if


?
0
 
Ryan ChongCommented:
try:

sqlcumle = "insert into tablename(Ad,Tel,Eposta,Sehir,Mark,Konu,Adres,Promosyon)  values('" & ad & "','" & tel & "','" & email & "','" & sehir & "','" & mark& "','" & konu & "','" & adres & "','" & promosyon & "')"
con.execute sqlcumle
 
sqlcumle2= "Select MAX(id) FROM tablename"
set rs = con.execute(sqlcumle2)
id2=rs(0)

...
0
 
BRMarketingAuthor Commented:
thank you for your promt reply.

I tried. But it did not work.

the Error message is:

 ADODB.Recordset error '800a0cc1'

Item cannot be found in the collection corresponding to the requested name or ordinal.
0
 
BRMarketingAuthor Commented:
Error mesage is about line 360 which is id2=rs(0)
thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.