Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
can we two different readers in two nested while loops

the code is below and m use c#.net and ms access

string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ui.mdb";
          OleDbConnection connst = new OleDbConnection(conn);
          connst.Open();
          string str = "select * from Tabs ";




          OleDbCommand cmd = new OleDbCommand(str, connst);

          OleDbDataReader DataReader = cmd.ExecuteReader();
     while (DataReader.Read())
          {

              TabID = Convert.ToInt32(DataReader[0]);
              TabName = DataReader[1].ToString();
              TabCaption = DataReader[2].ToString();
              TabHome = RibbonBar.InsertTab(TabID, TabCaption);
              TabHome.Id = TabID;

              OleDbDataReader ReadGroup;
              do
              {
                  string str1 = "select * from Groups where Tab_ID=" + TabID;
                  OleDbCommand CmdGroup = new OleDbCommand(str1, connst);

                  ReadGroup = CmdGroup.ExecuteReader();
                  ReadGroup.Read();
                  Console.WriteLine(ReadGroup.HasRows);
              }


              while (ReadGroup.Read());
              {
                  GroupID = Convert.ToInt32(ReadGroup[0]);
                  GroupName = ReadGroup[1].ToString();
                  GroupCaption = ReadGroup[2].ToString();
                  Tests = TabHome.Groups.AddGroup(GroupCaption, GroupID);

                  //for (int k = j; k <= i; k++)
                  //{
                  string str2 = "select * from Items where Group_id=0";
                  OleDbCommand CmdControls = new OleDbCommand(str2, connst);
                  OleDbDataReader ReadControl = cmd.ExecuteReader();
                  while (ReadControl.Read())
                  {
                      ControlID = Convert.ToInt32(ReadControl[0]);
                      ControlName = ReadControl[1].ToString();
                      XtremeCommandBars.XTPControlType typ = (XtremeCommandBars.XTPControlType)ControlID;
                      Tests.Add(typ, ControlID, ControlName, false, false);
                      Console.WriteLine(XtremeCommandBars.XTPControlType.xtpControlButton.GetTypeCode());
                      int lm;
                      lm = Convert.ToInt32(typ.GetTypeCode());

                  }
              }
                //}
          }
Posted
Updated 7-Feb-10 22:59pm
v3

Sure - knock yourself out.

If you want a more detailed answer, post your code, tell us what language you're using ( is it VBScript or not ? ), and explain what you're trying to do, and where it's going wrong.
 
Share this answer
 
Please format your code properly; use the "code block" button and make sure the entire code block is within the <pre></pre> tags. You can check it after you do this with the "Quick Preview" tab.
 
Share this answer
 
I don't see any reason for this not to work. I assume you think it's not working, so perhaps you need to tell us what doesn't work, what you expect it to do, what you've learned through debugging the code, etc.

The braces around GroupID = Convert.ToInt32(ReadGroup[0]); down to the ReadControl.Read() loop, make the code hard to read, because you have a while statment above them and it takes a second to realise it's attached to a do. The braces add nothing and hurt readability, I'd lose them.
 
Share this answer
 
cshuhh wrote:
can we two different readers in two nested while loops


That wouldn't be possible according to the documentation;
While the SqlDataReader is being used, the associated SqlConnection is busy serving the SqlDataReader, and no other operations can be performed on the SqlConnection other than closing it. This is the case until the Close method of the SqlDataReader is called.
.

The alternative would be to replace one of the readers with a DataSet, or to open a second connection.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900