1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to show SQL command retrieve in an ASP/HTML table

Discussion in 'C#' started by tiagozn, Aug 9, 2008.

  1. #1
    Hi there,

    I'm so new in ASP dev and would like to know how to show in an HTML/ASP table, data retrieved from a SQL command (DataBase). It's about a crossed-reference data.

    e.g.:
    I got this ASP code below:

    set rs = conn.execute("TRANSFORM Sum(dados.test) AS SumOfTest SELECT dados.spo FROM dados GROUP BY dados.spo PIVOT Format([date])")

    This SQL command retrieve a crossed-reference table, with labels in lines and columns and values for each line, according to the column.

    I want to show something like that:
    SPO 8/1 8/2 8/3
    value1 10 15 16
    value2 12 13 18

    And my doubt is: How to "create" this table in HTML/ASP code, after i got the retrieve of DB?

    If anyone could help me, I'll appreciate!!
     
    tiagozn, Aug 9, 2008 IP
  2. vccseller

    vccseller Active Member

    Messages:
    932
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    95
    #2
    You CAN use a data grid view, or you might have to use the dynamic tool creation.

    Using tables.rows.add if i m not wrong.
     
    vccseller, Aug 10, 2008 IP
  3. tiagozn

    tiagozn Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the time!

    But i'm don't know how to do that?

    There is some example that can I follow?
     
    tiagozn, Aug 10, 2008 IP
  4. vihutuo

    vihutuo Well-Known Member

    Messages:
    1,511
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    180
    #4
    You will need to iterate through the recordset and build the table using HTML tags. Something like this

    mytable="<TABLE>"
    while not rs.EOF
    mytable=mytable & "<TR><TD>" & rs (0) & "<\TD>" & rs(1) & "<\TD><\TR>"
    rs.MoveNext()
    wend

    mytable=mytable & "<\TABLE>"
    response.write mytable


    If you dont know the number of columns use a for loop to build the columns

    for i=0 to rs.fields.count-1
    'Build columns here
    Next
     
    vihutuo, Aug 11, 2008 IP
  5. SNK111

    SNK111 Guest

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Check this link: shahriarnk.com/Shahriar-N-K-Research-Embedding-SQL-in-C-Sharp-Java.html for details on how to connect to SQL server database from C#.NET database applications as well as Java database applications. It also describes how to pass embedded SQL queries using SQLCommand, calling stored procedures, pass parameter etc.

    shahriarnk.com
     
    SNK111, Apr 5, 2010 IP