views:

59

answers:

2

What code would put the results of the query (or any query) into an HTML table?

ReadOnly QUERY As String = "SELECT * FROM DUAL"

Public Sub page_load()
    Dim myConn As New OracleConnection( _
        ConfigurationManager.ConnectionStrings("DB").ConnectionString)
    myConn.Open()

    Dim myCommand As New OracleCommand(QUERY, myConn)
    Dim myReader As OracleDataReader
    myReader = myCommand.ExecuteReader()

    'Insert Code Here'

    myConn.Close()
End Sub
+1  A: 

Loop over the reader using the boolean Read method:

while (myReader.Read())
{
    'Write out to html, or populate server side controls.
    'use myReader.GetXxx(index) methods here to get to the data
}
Oded
+2  A: 

First... add a table to your markup using <asp:Table id="myTable" runat="server"></asp:Table>

Then in your code, try this:

While myReader.Read
  Dim myRow as HTMLTableRow = New HTMLTableRow

  For i as Integer = 0 to myReader.FieldCount- 1
    Dim myCell as HTMLTableCell = New HTMLTableCell

    myCell.InnterText = myReader.GetString(i)

    myRow.Cells.Add(myCell)
  Next i

  myTable.Rows.Add(myRow)
End While
Sonny Boy
As a side note, you may be better off using an IDataReader instead of your OracleDataReader object unless specific functionality is needed. This will help to make your code more generic and portable.
Sonny Boy