DB Record As Comma Delimited String

Discussion in 'ASP General' started by rn5a@rediffmail.com, Apr 27, 2007.

  1. Guest

    A MS_Access DB table has 3 columns - ID, UID & Location. ID is an
    AutoNumber column, UID is a foreign key (the primary key UID column
    resides in another table). Each UID can have multiple entries under
    the Location column something like this:

    ---------------------------
    UID Location
    ---------------------------
    2 China
    2 Japan
    2 Austria
    2 India
    2 Denmark
    3 USA
    3 UK
    3 Korea
    ---------------------------

    I want an ASP page to retrieve the above records based on the UID. For
    e.g. if the UIO is 2, then China, Japan, Austria, India & Denmark
    should be retrieved but I don't want the ASP page to display the
    records in the same way as the DB table displays. Rather I want the
    records to be displayed on the ASP page like this (assuming that
    UID=2)

    ---------------------------
    2 - China, Japan, Austria, India, Denmark
    ---------------------------

    If UID=3, then the ASP page should display the records like this:

    ---------------------------
    3 - USA, UK, Korea
    ---------------------------

    How do I implement this?
     
    , Apr 27, 2007
    #1
    1. Advertising

  2. wrote:
    > A MS_Access DB table has 3 columns - ID, UID & Location. ID is an
    > AutoNumber column, UID is a foreign key (the primary key UID column
    > resides in another table). Each UID can have multiple entries under
    > the Location column something like this:
    >
    > ---------------------------
    > UID Location
    > ---------------------------
    > 2 China
    > 2 Japan
    > 2 Austria
    > 2 India
    > 2 Denmark
    > 3 USA
    > 3 UK
    > 3 Korea
    > ---------------------------
    >
    > I want an ASP page to retrieve the above records based on the UID. For
    > e.g. if the UIO is 2, then China, Japan, Austria, India & Denmark
    > should be retrieved but I don't want the ASP page to display the
    > records in the same way as the DB table displays. Rather I want the
    > records to be displayed on the ASP page like this (assuming that
    > UID=2)
    >
    > ---------------------------
    > 2 - China, Japan, Austria, India, Denmark
    > ---------------------------
    >
    > If UID=3, then the ASP page should display the records like this:
    >
    > ---------------------------
    > 3 - USA, UK, Korea
    > ---------------------------
    >
    > How do I implement this?


    <%
    dim cn, cmd, rs, sSQL,sHTML,uid
    uid=2 'you will probably get this value from request
    sHTML = uid & " - "
    set cn=createobject("adodb.connection")
    cn.open "provider=microsoft.jet.oledb.4.0;" & _
    "data source=p:\ath\to\database.mdb"
    sSQL="select Location From tablename " & _
    "where UID=?"
    set cmd=createobject("adodb.command")
    with cmd
    set .activeconnection=cn
    .commandtext=sSQL
    .commandtype=1 'adCmdText
    end with
    set rs=cmd.execute(,array(uid))
    if not rs=nothing then
    sHTML = sHTML & rs.getstring(2,,, ", ")
    end if
    rs.close:set rs= nothing
    cn.close:set cn=nothing
    response.write sHTML
    %>
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Apr 27, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yama

    Comma Delimited

    Yama, Dec 15, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    400
    Ken Cox [Microsoft MVP]
    Dec 16, 2003
  2. Luis Esteban Valencia

    Read Comma Delimited File

    Luis Esteban Valencia, Jul 27, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,812
    Paul Clement
    Jul 27, 2005
  3. Edward A Thompson

    JavaMail MimeMessage - comma delimited?

    Edward A Thompson, Oct 8, 2003, in forum: Java
    Replies:
    9
    Views:
    5,629
    GaryM
    Oct 10, 2003
  4. electrixnow

    parse comma delimited text string

    electrixnow, Feb 7, 2006, in forum: C++
    Replies:
    25
    Views:
    1,188
    Alf P. Steinbach
    Feb 8, 2006
  5. RyanL
    Replies:
    6
    Views:
    690
    Paul McGuire
    Aug 28, 2007
Loading...

Share This Page