Forums
This topic is locked
getting last inserted record without passing id
Posted 23 Nov 2006 19:19:00
1
has voted
23 Nov 2006 19:19:00 Dave Clarke posted:
I have tried various tutorials on passing the id of the record just inserted but can't seem to get any to work.. soI have 2 tables (Members & Apartments), both have a members id field (fldMemberID), when a member inserts a new apartment their id (Members.fldMemberID) is inserted into Apartments.fldMemberID, so we know which member inserted which apartment.. ok?
once the apatment has been inserted they are sent to a page with the option to upload pictures, so now we need to know which apartment they inserted last in order to upload the pics to the correct apartment (each member can have as many apartments as they want), so i have come up with this recordset, i was wondering if anybody can confirm that this would work correctly.
<pre id=code><font face=courier size=2 id=code><b>
<%
Dim RSlastapart__MM_ColParam
RSlastapart__MM_ColParam = "1"
If (Session("MM_Username" <> "" Then
RSlastapart__MM_ColParam = Session("MM_Username"
End If
%>
<%
Dim RSlastapart
Dim RSlastapart_numRows
Set RSlastapart = Server.CreateObject("ADODB.Recordset"
RSlastapart.ActiveConnection = MM_ConnTenerife_STRING
RSlastapart.Source = "SELECT TOP 1 * FROM Apartments LEFT OUTER JOIN Members ON
Apartments.fldMemberID = Members.fldMemberID WHERE Members.fldusername = '"
+ Replace(RSlastapart__MM_ColParam, "'", "''" + "'
ORDER BY Apartments.fldAptID DESC"
RSlastapart.CursorType = 0
RSlastapart.CursorLocation = 2
RSlastapart.LockType = 1
RSlastapart.Open()
RSlastapart_numRows = 0
%>
</b></font id=code></pre id=code>
thanks
DW8.02|ASP|VBScript|IIS5.1|Access|WinXPPro & WinXPHome.
www.reunite.co.uk
Edited by - Davecl on 23 Nov 2006 19:20:41
Edited by - Davecl on 23 Nov 2006 19:21:35
Replies
Replied 24 Nov 2006 17:01:46
24 Nov 2006 17:01:46 Vince Baker replied:
Hi Dave,
That will work fine. There is a slight possibility that user 2 could submit the form instantaniously after user 1 had and this would cause user 1 & 2 to be using user 2's details but the chances are so remote that it is not worth considering.
may well be worth adding the user name as well to avoid that senario so you would search for the highest id but where the username matches? This would ensure the above senario is avoided if there would be very heavy traffic on the site.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
That will work fine. There is a slight possibility that user 2 could submit the form instantaniously after user 1 had and this would cause user 1 & 2 to be using user 2's details but the chances are so remote that it is not worth considering.
may well be worth adding the user name as well to avoid that senario so you would search for the highest id but where the username matches? This would ensure the above senario is avoided if there would be very heavy traffic on the site.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
Replied 26 Nov 2006 08:07:31
26 Nov 2006 08:07:31 Dave Clarke replied:
cheers Vince
I am already using Session(MM_username) to make sure the user gets their own last record
<pre id=code><font face=courier size=2 id=code>
Dim RSlastapart__MM_ColParamRSlastapart__MM_ColParam = "1"If (Session("MM_Username" <> ""
Then RSlastapart__MM_ColParam = Session("MM_Username" End If
</font id=code></pre id=code>
<pre id=code><font face=courier size=2 id=code>
RSlastapart.Source = "SELECT TOP 1 * FROM Apartments LEFT OUTER JOIN Members ON
Apartments.fldMemberID = Members.fldMemberID
<font color=red>WHERE Members.fldusername = '" + Replace(RSlastapart__MM_ColParam, "'", "''" + "'</font id=red>
ORDER BY Apartments.fldAptID DESC"
</font id=code></pre id=code>
or did you mean something different?
DW8.02|ASP|VBScript|IIS5.1|Access|WinXPPro & WinXPHome.
www.reunite.co.uk
Edited by - Davecl on 26 Nov 2006 08:08:22
Edited by - Davecl on 26 Nov 2006 08:09:10
Edited by - Davecl on 26 Nov 2006 08:09:39
I am already using Session(MM_username) to make sure the user gets their own last record
<pre id=code><font face=courier size=2 id=code>
Dim RSlastapart__MM_ColParamRSlastapart__MM_ColParam = "1"If (Session("MM_Username" <> ""
Then RSlastapart__MM_ColParam = Session("MM_Username" End If
</font id=code></pre id=code>
<pre id=code><font face=courier size=2 id=code>
RSlastapart.Source = "SELECT TOP 1 * FROM Apartments LEFT OUTER JOIN Members ON
Apartments.fldMemberID = Members.fldMemberID
<font color=red>WHERE Members.fldusername = '" + Replace(RSlastapart__MM_ColParam, "'", "''" + "'</font id=red>
ORDER BY Apartments.fldAptID DESC"
</font id=code></pre id=code>
or did you mean something different?
DW8.02|ASP|VBScript|IIS5.1|Access|WinXPPro & WinXPHome.
www.reunite.co.uk
Edited by - Davecl on 26 Nov 2006 08:08:22
Edited by - Davecl on 26 Nov 2006 08:09:10
Edited by - Davecl on 26 Nov 2006 08:09:39
Replied 27 Nov 2006 10:59:05
27 Nov 2006 10:59:05 Vince Baker replied:
Maybe I should spend more time ready the post! Exactly what I meant.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
Replied 29 Nov 2006 17:05:33
29 Nov 2006 17:05:33 Dave Clarke replied:
hehehe <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
DW8.02|ASP|VBScript|IIS5.1|Access|WinXPPro & WinXPHome.
www.reunite.co.uk
DW8.02|ASP|VBScript|IIS5.1|Access|WinXPPro & WinXPHome.
www.reunite.co.uk