Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0how can i do a nested datareader ?how can i do a nested datareader ?
Previous
 
Next
New Post
4/14/2009 4:41 PM
 

 my question is very simple how can I do a nested datareader in my VB code , when i did an error message has been performed and told me "There is already an open DataReader associated with this Command which must be closed first." , please look at the folowing code (is very simple) for information

 

------------------------vb code-----------------

 

 Dim myConnection As SqlConnection = New SqlConnection("server=ISITC-A31266378;uid=dnnuser40;pwd=1311984;database=DotNetNuke40")

        Dim myCommand As SqlCommand

        Dim dr As SqlDataReader

 

        'establishing connection. you need to provide password for sql server

        myConnection.Open()

        'opening the connection

        'myCommand = New SqlCommand("SELECT TabName FROM Tabs WHERE ParentId = 69", myConnection)

        myCommand = New SqlCommand("SELECT TabName, TabID, ParentID FROM Tabs WHERE ParentId = 63", myConnection)

        'executing the command and assigning it to connection 

        dr = myCommand.ExecuteReader()

 

        While dr.Read()

            'reading from the datareader

            Response.Write(dr(0).ToString() & " ")

            Response.Write(dr(1).ToString() & " ")

            Response.Write(dr(2).ToString() & " ")

 

            Dim myCommand2 As SqlCommand

            Dim dr2 As SqlDataReader

            myCommand2 = New SqlCommand("SELECT TabName FROM Tabs WHERE ParentId = " & dr(1), myConnection)

            dr2 = myCommand2.ExecuteReader()

 

            While dr2.Read()

                Response.Write(dr2(0).ToString() & " -  ")

            End While

            dr2.Close()

 

        End While

        dr.Close()

        myConnection.Close()

 
New Post
4/14/2009 4:51 PM
 

You'll need MultipleActiveResultSets=True in your connectionString (in web.config or your code), as in:

<add name="yourDB" 
   connectionString="... (other stuff)... MultipleActiveResultSets=True;"
   providerName="System.Data.SqlClient"
 
New Post
4/14/2009 6:39 PM
 

 when I try to with your tips in the config file the debager made underline to  MultipleActiveResultSets="true and tell me that the  MultipleActiveResultSets attribute is not declared soo how can i declared this attribute and where

and this is a portion where I put the attribute in the config file 

 

<connectionStrings>

<add name="SiteSqlServer" connectionString="Data Source=ISITC-A31266378;Initial Catalog=DotNetNuke40;User ID=dnnuser40;Password=1311984" providerName="System.Data.SqlClient" />

<add name="DotNetNuke40ConnectionString1" connectionString="Data Source=ISITC-A31266378;Initial Catalog=DotNetNuke40;Integrated Security=True" MultipleActiveResultSets=True; providerName="System.Data.SqlClient" />

</connectionStrings>

 
New Post
4/14/2009 8:54 PM
 

MultipleActiveResultSets=True is part of the connection string, it is NOT an attribute.

connectionString="Data Source=ISITC-A31266378;Initial Catalog=DotNetNuke40;Integrated Security=True;MultipleActiveResultSets=True;"

 
New Post
4/14/2009 10:26 PM
 

 after doinig a lot of googling I realized that is not possible to do a nested loop with a datareder I found a solution by using the dataset like this 

 

 Dim DBConn As SqlConnection = New SqlConnection("server=ISITC-A31266378;uid=dnnuser40;pwd=1311984;database=DotNetNuke40")

        Dim DBCommand As SqlDataAdapter = New SqlDataAdapter("SELECT TabName, TabID, ParentID FROM Tabs WHERE ParentId = 63", DBConn)

        Dim DSPageData As New DataSet

 

        Dim i As Long

        Dim j As Long

        DBCommand.Fill(DSPageData, "Tabs")


        For i = 0 To DSPageData.Tables("Tabs").Rows.Count - 1 'Code to process record

            Response.Write("<BR>Processed Record: " & DSPageData.Tables("Tabs").Rows(i).Item("TabName"))


            Dim DBCommand1 As SqlDataAdapter = New SqlDataAdapter("SELECT TabName FROM Tabs WHERE ParentId = " & DSPageData.Tables("Tabs").Rows(i).Item("TabID"), DBConn)

            Dim DSPageData1 As New DataSet

            DBCommand1.Fill(DSPageData1, "Tabs")

            For j = 0 To DSPageData1.Tables("Tabs").Rows.Count - 1 'Code to process record

                Response.Write("<BR>Child Record: " & DSPageData1.Tables("Tabs").Rows(j).Item("TabName"))

            Next

        Next

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0how can i do a nested datareader ?how can i do a nested datareader ?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out