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 retrieve values from sql server to ASP?

Discussion in 'C#' started by computerzworld, Apr 17, 2007.

  1. #1
    Hi. I want to retrieve values from a table which is in sql server to ASP page. How to do this? Please tell me.Thanks in advance.
     
    computerzworld, Apr 17, 2007 IP
  2. sparksflying

    sparksflying Peon

    Messages:
    1,066
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    0
  3. sparksflying

    sparksflying Peon

    Messages:
    1,066
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    0
    #3
    sparksflying, Apr 17, 2007 IP
  4. computerzworld

    computerzworld Active Member

    Messages:
    214
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #4
    connection and all other things are OK but I want to retrieve the values in table format from sql server to ASP.
     
    computerzworld, Apr 17, 2007 IP
  5. druidelder

    druidelder Peon

    Messages:
    285
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If you are using ADO then this will help:


    <%
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.whatever"
    conn.Open(Server.Mappath("/whatever.mdb"))

    set rs = Server.CreateObject("ADODB.recordset")
    rs.Open "SELECT whatever", conn
    %>

    <table border="1" width="100%">
    <%do until rs.EOF%>
    <tr>
    <%for each x in rs.Fields%>
    <td><%Response.Write(x.value)%></td>
    <%next
    rs.MoveNext%>
    </tr>
    <%loop
    rs.close
    conn.close
    %>

    I usd 'whatever' as text to be replaced. If you want a header for the table, create it before the do until loop. You might also add an else clause to display when there are no records.
     
    druidelder, Apr 17, 2007 IP
  6. computerzworld

    computerzworld Active Member

    Messages:
    214
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #6
    thank you all.
     
    computerzworld, Apr 17, 2007 IP
  7. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #7
    retrieve the data as a table? As in a DataTable? If you use strongly typed datasets, you can create a datatble directly filled from your query. Then you can directly bind that datatable to a gridview (or whatever control you want) :)
     
    ccoonen, Apr 17, 2007 IP
  8. jimrthy

    jimrthy Guest

    Messages:
    283
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ccoonen, I'm pretty sure they're talking about classic ASP.

    But still...datasets and typed datasets are fine, but most of the programmers I know who have dealt with a lot of pain involved with debugging them in complex scenarios (say, tracing them across multiple web service calls) highly recommend just using custom business objects instead.

    (Not that that's relevant to this thread, I don't think).
     
    jimrthy, Apr 21, 2007 IP