1

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
2
  • 1
    There's nothing in DUAL, SELECT * won't return any columns Commented Dec 29, 2009 at 19:17
  • 3
    @OMG Ponies: That's absolutely not true. DUAL has one column (DUMMY) and one row. Commented Dec 29, 2009 at 19:23

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

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.
1

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
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.