Hi All,

I am getting the error "There is already an open DataReader associated with this Command which must be closed first.
"

protected void Page_Load(object sender, EventArgs e)
        {
            nbseapi nbsi = new nbseapi();
            Guid guid = new Guid();
             
            if (Request.QueryString["Id"] != null)
            {
                string Id = Request.QueryString["Id"];
               

                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SimplifyNew"].ToString()))
                {

                    SqlCommand cmd = new SqlCommand("uspSelectOrder", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    
                    cmd.Parameters.Add(new SqlParameter("@CompId", SqlDbType.VarChar)).Value = Id;
                    conn.Open();
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {


                        string strId = reader["BundleIds"].ToString();
                       string [] str1=strId.Split(',');

                       foreach (string id in str1)
                        {
                            string BundleID = id;

                            string strNode = reader["FieldOrdering"].ToString();
                            string[] str2 = strNode.Split(',');
                            foreach(string nodes in str2)
                            {
                                BundleSearchResultStruct BundleSearchResult = nbsi.GetProductDetails(guid, "marketingPartnerPassword", Convert.ToInt32(BundleID));
                             using (SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["SimplifyNew"].ToString()))
                             {
                              SqlCommand cmd1 = new SqlCommand("usp_selectnodes", conn);
                                 cmd.CommandType = CommandType.StoredProcedure;
                                  cmd.Parameters.Add(new SqlParameter("@node", SqlDbType.VarChar)).Value = nodes;
                                  conn1.Open();
                                  SqlDataReader reader1 = cmd.ExecuteReader();

                                 while (reader.Read())
                                 {
                                      
                                   TableRow tRow = new TableRow();
                                   Table1.Rows.Add(tRow);  
                                      
                                     int id1=Convert.ToInt32(id);
                                     for(int cellcntr=1;cellcntr<=id1;cellcntr++)
                                     {
                                     TableCell tCell = new TableCell();
                                      tRow.Cells.Add(tCell);
                                     
                                     }
                                     int nodes1=Convert.ToInt32(nodes);
                                      for(int rowCtr=1; rowCtr <= nodes1; rowCtr++)
                                      {
                                     TableRow tRow1 = new TableRow();
                                     Table1.Rows.Add(tRow1); 

                                          TableCell tCell = new TableCell();
                                           tRow.Cells.Add(tCell); 
                                            tCell.Text=reader["Description"].ToString();
                                              for(int cellcntr=1;cellcntr<=id1;cellcntr++)
                                                {
                                                    TableCell tCell1 = new TableCell();
                                                    tRow.Cells.Add(tCell1);
                                                  //string prp=reader["XmlName"].ToString();
                                                  //tCell1.Text = BundleSearchResult.

                                                    Type type = BundleSearchResult.GetType();
                                                    PropertyInfo senderproperty = type.GetProperty(reader["XmlName"].ToString());

                                                    object PropertyValue = senderproperty.GetValue(BundleSearchResult, null);
                                                    tCell1.Text = PropertyValue.ToString();

                                                    
                                     
                                                }

                                      }
                                     
                                     
                                 
                                 }
                                 reader1.Close();
                                   conn1.Close();
                             
                             }
                            
                            
                            }
                             

                           

                               
                               }
                           
                           }
                    reader.Close();
                         conn.Close();
                    
                           }

Please help

Thanks,
sniigg

Line 39 should be like this
SqlCommand cmd1 = new SqlCommand("usp_selectnodes", conn1);

Thanks a lot...silly me :):)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.