If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > last record

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-18-04, 00:48
fisya fisya is offline
Registered User
 
Join Date: Mar 2004
Posts: 53
Unhappy last record

hi...
how i want to get data from the last record after i have do the sql command(select).
anybody have any idea.....please help me
Reply With Quote
  #2 (permalink)  
Old 05-18-04, 01:16
MrWizard MrWizard is offline
Registered User
 
Join Date: Mar 2003
Location: Atlanta, GA
Posts: 191
Conn={your connection string}
Set Q = Server.CreateObject("ADODB.Connection")
Q.Open Conn
Set rsQ = Server.CreateObject("ADODB.Recordset")
rsQ.Open "Your SQL Statement", Q
rsQ.MoveLast ' <=== this moves you to the last record in the SQL result data

... and after you've done all you need to do,
rsQ.Close: Set rsQ=Nothing
Q.Close: Set Q=Nothing


Tim
__________________
Tim
Reply With Quote
  #3 (permalink)  
Old 05-18-04, 03:01
fisya fisya is offline
Registered User
 
Join Date: Mar 2004
Posts: 53
Unhappy how...

how i want to implement this coding...below i attach my coding

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%
Dim aduan
Dim id
Dim pengguna
Dim code
Dim sbb
Dim lok
Dim blok
Dim ting
Dim bil
Dim tarikh
Dim sq
Dim db
Dim sq2
Dim sq3
Dim rs

aduan=request.form("textfield")
pengguna=request.form("textfield")
code=request.form("kerosakan")
sbb=request.form("textfield3")
lok=request.form("select")
blok=request.form("blok")
ting=request.form("tingkat")
bil=request.form("bilik")
tarikh=request.form("tarikh")

set db = Server.CreateObject ("ADODB.Connection")
db. Open "sambung"

sq2="select id_aduan from tb_arkib"
set rs=db.execute(sq2)
rs.movelast
aduan=rs("count")

aduan=aduan+1
'rs("count")=aduan

sq= "INSERT INTO tb_arkib(id_aduan, id_user, kod_kerosakan, sebab_kerosakan, lokasi, blok, tingkat, no_bilik, tarikhmasa) VALUES ('" & aduan & "', '" & pengguna & "', '" & code & "', '" & sbb & "' ,'" & lok & "' ,'" & blok & "','" & ting & "','" & bil & "','" & tarikh & "')"
set rs = db.execute(sq)

db.close

Response.Redirect ("timakasih.asp")
%>

</body>
</html>
Reply With Quote
  #4 (permalink)  
Old 05-18-04, 04:09
MrWizard MrWizard is offline
Registered User
 
Join Date: Mar 2003
Location: Atlanta, GA
Posts: 191
I guess I must be missing something, as what you are doing makes no sense to me.

It seems that you are just incrementing a single field to count records.... why not just set the field as an autocount field?

You can also just use rs.recordcount to get the number of records, if that's what you're after... without having to do another SQL query.

I guess I just don't get the purpose of your code.

Tim
__________________
Tim
Reply With Quote
  #5 (permalink)  
Old 05-18-04, 11:28
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
Right.. I think what we're lacking is what he's attempting to accomplish, and the problem he's having...

Fisya.. you should be using an Identity column in his SQL server to generate that ID, not your code... I've said this before in a prior post for this same bit of code... whether the code works or not, this is not the optimal way to do it.

Follow up on your prior posts:
http://www.dbforums.com/t997627.html
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #6 (permalink)  
Old 05-19-04, 00:42
fisya fisya is offline
Registered User
 
Join Date: Mar 2004
Posts: 53
Talking settle

ok tq my problem already settle now i can pass up my system to my bos.......enjoyyyyy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On