Results 1 to 6 of 6

Thread: last record

  1. #1
    Join Date
    Mar 2004
    Posts
    53

    Unhappy Unanswered: 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

  2. #2
    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

  3. #3
    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>

  4. #4
    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

  5. #5
    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.

  6. #6
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •