What code would put the results of the query (or any query) into an HTML t开发者_JS百科able?
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
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
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
}
精彩评论