locked
how do i response.write a table with my records from an Access DB RRS feed

  • Question

  • User651828378 posted

    Hi.

    Im using this connections, its works fine, my question is, if i got "lets say" 9 records,

    How do i then response.write a table with 4 colums and then 3 rows where there is nothing in the last 3 cells of the last row.

    So it will make a row then 4 colums with 4 diffrent records, and then make a new row, with 4 colums with again 4 new diffrent records and then make the last row with the 9. (last) record, and then finish the table, with no data in the last 3 cells in this row.

    How can i do that with this connection setup.

    Dim strSQL As String = ""
    
            strSQL = "" & _
            "SELECT * " & _
            "FROM news_users" 
    
            Using connection As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString)
                Using command As OleDbCommand = New OleDbCommand(strSQL, connection)
                    command.Connection.Open()
                    Using reader As OleDbDataReader = command.ExecuteReader(CommandBehavior.CloseConnection)
                        If reader.HasRows Then
                            Do While reader.Read()
                                Response.Write(reader("test_cat") & " " & reader("test_info"))
                            Loop
                        Else
                            Response.Write("Ingen data i db")
                        End If
                    End Using
                End Using
            End Using



    Tuesday, May 22, 2012 11:51 AM

Answers

  • User-661350001 posted
    After
     If reader.HasRows Then
    Dim strBldr as new StringBuilder
    strBldr.Append("<table>")
    
    Do While reader.Read()
    strBldr.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>",reader("test_cat"),reader("test_info"))
    Loop
    
    strBldr.Append("</table>")
    Response.Write(strBldr.ToString())
    Else
    Response.Write("Ingen data i db")
    End IF


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 22, 2012 12:04 PM
  • User3866881 posted

    is it then

    strBldr.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>",reader("test_cat"))

    First I want to say that your syntax seems right,so you can have a try to output it……

    But sorry to say that this isn't a good way to use Response.Write just like you are now using asp instead of asp.net……I think you can use GridView——Just according to the wizard or some very easy torturial they will aid you to output a beautiful data contents with things……

    For more you can refer the GridView's torturial(Sample is using SqlDataSource,but you can use AccessDataSource instead if you are using Access's DB……)

    http://msdn.microsoft.com/en-us/library/bb288032.aspx#aspnett12ustmpfldsvb_topic2

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 23, 2012 10:37 PM

All replies

  • User-661350001 posted
    After
     If reader.HasRows Then
    Dim strBldr as new StringBuilder
    strBldr.Append("<table>")
    
    Do While reader.Read()
    strBldr.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>",reader("test_cat"),reader("test_info"))
    Loop
    
    strBldr.Append("</table>")
    Response.Write(strBldr.ToString())
    Else
    Response.Write("Ingen data i db")
    End IF


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 22, 2012 12:04 PM
  • User651828378 posted

    Hi thx for reply, what if its only reader("test_cat") that i will show but in all the 4 cells

    So i show this field

    Record1 Cell1 - Record2 Cell2 - Record3 Cell3 - Record4 Cell4

    is it then

    strBldr.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>",reader("test_cat"))
    



    Tuesday, May 22, 2012 3:35 PM
  • User3866881 posted

    is it then

    strBldr.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>",reader("test_cat"))

    First I want to say that your syntax seems right,so you can have a try to output it……

    But sorry to say that this isn't a good way to use Response.Write just like you are now using asp instead of asp.net……I think you can use GridView——Just according to the wizard or some very easy torturial they will aid you to output a beautiful data contents with things……

    For more you can refer the GridView's torturial(Sample is using SqlDataSource,but you can use AccessDataSource instead if you are using Access's DB……)

    http://msdn.microsoft.com/en-us/library/bb288032.aspx#aspnett12ustmpfldsvb_topic2

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 23, 2012 10:37 PM