Writing data from the DB to the page

andycharger

Well-known member
Joined
Apr 2, 2003
Messages
152
Im trying to put a table on my form to display a list of results from a plans table on my database.

However, I need to know how I get it to the screen.

Do I put the code for accessing the data in the code section or in the HTML section? Also how is best to put it into a table?

Here is my code so far:
Code:
 Dim oConn As SqlConnection
        Dim oComm As SqlCommand
        Dim oReader As SqlDataReader
        Dim sSQL As String
        Dim sConn As String
        Dim strDept As String

        strDept = Request.QueryString("dept_id")

        sSQL = "SELECT * "
        sSQL += "FROM Plans where department_id = " & strDept
        sConn = ConfigurationSettings.AppSettings("ConnectionString")

        oConn = New SqlConnection(sConn)
        oConn.Open()

        oComm = New SqlCommand(sSQL, oConn)
        oReader = oComm.ExecuteReader()

 **********writing the results to a table  I expect should go here *********

        oConn.Close()

Thanks!
 
or you can use the asp.net datagrid which has the format of a table. very simple. in the body of your html you stick:

<asp:datagrid id="dgresults" runat="server" />

then instead of this:

oReader = oComm.ExecuteReader()

put:

dgresults.datsource = oComm.executereader()
dgresults.databind ()


you dont even need the datareader object in this case.
 
Back
Top