Set Default Shipping Address

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • printedgoods
    New Member
    • Nov 2007
    • 9

    Set Default Shipping Address

    Hello All!

    I have a shipping profile page that i created and works perfectly. User can create multiple shipping addresses that post to an access DB and they can then edit them (1 at a time). I have all the appropriate java validators in place for the submit (that took about 300 lines of code :) ). I have it to where the user can only have one default address as well.

    The question that i have relates to auto entering a default shipping address.

    If one is not selected in the database i would like to loop throught the recordset and select the top 1. If the user deletes the default address i want to select the top 1. If one already exists then i want keep that one selected.

    I have been working on this for a while and have put it aside so i could reset my thoughts.


    Thanks for any help

    Jason
    Printedgoods
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    You don't need to loop through a recordset to get your top record. You can just use a quick SQL query to return a record set with only 1 record in it. (the top record) using the TOP syntax.

    [code=sql]

    SELECT TOP 1 * FROM ShippingAddress es

    [/code]

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      Jeff's right, and this is the fastest method. However if you don't remember the "Top 1" method and just say "SELECT *" you will get the top one if you don't loop.

      Jared

      Comment

      • printedgoods
        New Member
        • Nov 2007
        • 9

        #4
        I got it all figured out. It just took moving on to another page and coming back.

        Here is what i did though I ran the defaultaddressR S to get the address info then:

        Code:
        If defaultaddressRS.EOF Then
        defaultaddressRS.close
        set insertdefaultaddressRS = Server.CreateObject("ADODB.RecordSet")
        insertdefaultaddressQuery = "Select top 1 id from customer_addresses_shipping where customer_id = " & Request.Cookies("cur_account") 
        insertdefaultaddressRS.Open insertdefaultaddressQuery, dbConn, adOpenStatic, adLockReadOnly, adCmdText
        									
        udefault = (insertdefaultaddressRS.fields("id"))
        									
        set udefaultRS = Server.CreateObject("ADODB.RecordSet")
        udefaultQuery = "update customer_addresses_shipping set default = 'on' where id = " & udefault
        udefaultRS.Open udefaultQuery, dbConn, adOpenStatic, adLockReadOnly, adCmdText
        								
        Else
        defaultaddressRS.close	
        End If

        This worked like a charm and so far no broken page.

        Thanks
        Jason

        Comment

        Working...