ASP.NET Datareader

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kosal
    New Member
    • Feb 2007
    • 68

    ASP.NET Datareader

    Dear Sir/Madam

    I would linke you to help me as below:

    I want to using datareader and inside datareader I have datareader but I cannot.
    I using code as below but error can you help me.

    Code:
    Dim Category As String = "SELECT catgcode, catgName FROM tblCategories"
            Dim myCommand As New System.Data.SqlClient.SqlCommand(Category, DBTools.gCnn)
            Dim myReader As System.Data.SqlClient.SqlDataReader=Nothing 
            myReader = myCommand.ExecuteReader()
            While myReader.Read()
               Response.Write("<li><span class='folder'>&nbsp;"& myReader("catgName") &"</span>")
                Dim subCategory As String = "SELECT subCatgCode, subCatgName FROM tblSubCategories WHERE catgcode='"& myReader("catgCode") 
                Dim myCommand1 As New System.Data.SqlClient.SqlCommand(subCategory, DBTools.gCnn)
                Dim myReader1 As System.Data.SqlClient.SqlDataReader
                myReader1 = myCommand1.ExecuteReader()
                While myReader1.Read()
                Response.Write("<ul>")
                Response.Write("<li><span class='file'>&nbsp;"& myReader1("subCatgName") &"</span></li>")
                Response.Write("</ul>")
                End While
                myReader1.Close()
                Response.Write("</li>")
            End While
    
           myReader.Close()
           myReader=Nothing 
        DBTools.gCnn.Close()


    thanks
    Kosal
    Last edited by tlhintoq; Jan 1 '10, 08:49 AM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      I using code as below but error
      What is the error? On which line of code?

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Well I think that the error is that the content isn't showing up because they are using Response.Write( )

        Do not use Response.Write( ) in your VB.NET or C# code.
        Why?
        Well, it places the content in an invalid place in the page.
        For example, if you use Response.Write( ) in your VB/C# code it's likely that your output is going to look like:
        Code:
        <ul>
         <li><span class='folder'> Folder 1 stuff</span></li>
         <li><span class='folder'> Folder 2 stuff</span></li>
         <li><span class='folder'> Folder 3 stuff</span></li>
         <li><span class='folder'> Folder 4 stuff</span></li>
        </ul>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml"> 
         
        ....
        Notice how the content is Above the <html> and doctype tags? This is invalid page content.

        Instead of using Response.Write consider using the appropriate ASP.NET controls...like the ListView, or the Repeater control something.

        -Frinny

        Comment

        • Kosal
          New Member
          • Feb 2007
          • 68

          #5
          Dear Sir

          As above code error:

          While myReader1.Read( )
          Response.Write( "<ul>")
          Response.Write( "<li><span class='file'>&n bsp;"& myReader1("subC atgName") &"</span></li>")
          Response.Write( "</ul>")
          End While

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Kosal, what is the error message?
            If there is no error message then please explain what is wrong?

            -Frinny

            Comment

            Working...