Problem retrieving correct order number

Discussion in 'C#' started by photoatlarge, Aug 21, 2009.

  1. #1
    I have a business website with a shopping cart and access database.
    I added some code to the customer order confirmation page that passes the customer order number to the following image upload page.
    This identifies the uploaded image with an order number and works fine if this is the customers first order.
    If the order is placed by a repeat customer, the oldest order number is retrieved, not the most recent.

    Can you please view the added code below and tell me if there is a way to fix this problem.

    Thanks!

    Code on confirmation page:

    <A href="ImageUpload.asp?orderno=<%=orderno %>">upload page</A>
    Code (markup):
    Code in upload page:

    <b>Order number: </b>
    <%
    'if no order number found, display box to enter it
    If (Request.QueryString("orderno") = "") Then
      %><input type="text" name="orderno" size="7" value=""><%
    Else
      %><input type="hidden" name="orderno" value="<%=Request.QueryString("orderno")%>"><% response.write( Request.QueryString("orderno") )
    End If %>
    Code (markup):
    Code that queries the database:

    'Get current order number.
    Set rsmod = Server.CreateObject("ADODB.Recordset")
    rsmod.Open "Select * From orders WHERE id=" & checksqln(orderid) & " ORDER BY orderDate DESC", DB, 1, 3 orderno=rsmod("orderno")
    cctype=rsmod("cctype")
    rsmod.Close
    set rsmod=nothing
    Code (markup):
    The added code that sorts the records in reverse order does not seem to change anything.
     
    photoatlarge, Aug 21, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Wouldn't you retrieve the records WHERE id = customerID not orderID ???
     
    camjohnson95, Aug 24, 2009 IP
  3. sibangor

    sibangor Peon

    Messages:
    6
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    use your unique customerid
     
    sibangor, Aug 28, 2009 IP
  4. BrightMinds

    BrightMinds Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    As long as you are calling the procedure after the order insert, the following should work...

    try..

    "Select * From orders WHERE CustomerID = " & CustomerID & " ORDER BY OrderID DESC"
     
    BrightMinds, Aug 31, 2009 IP
  5. alexpr07

    alexpr07 Active Member

    Messages:
    284
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    73
    #5
    Try adding "LIMIT 1" at the end of SQL query.
     
    alexpr07, Sep 2, 2009 IP
  6. rahulwb

    rahulwb Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    use select top 1 * From orders WHERE CustomerID = " & CustomerID & " ORDER BY OrderID DESC"
     
    rahulwb, Oct 5, 2009 IP