Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
here is the code and the problem is that the second reader i.e ReadGroup
Fail to read data

code:-


MIDL
int TabID, GroupID, ItemID, ControlID;
           String TabName, TabCaption, GroupName, GroupCaption, ItemName, ItemCaption, ControlName, ControlCaption;
           string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ui.mdb";
           OleDbConnection connst = new OleDbConnection(conn);
           connst.Open();
           string str = "select * from Tabs ";



while (DataReader.Read())
{

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


string str1 = "select * from Groups where Tab_ID=" + TabID;
OleDbCommand CmdGroup = new OleDbCommand(str1, connst);
OleDbDataReader 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 8-Feb-10 6:42am
v2

MSDN[^] states:
While the OleDbDataReader is being used, the associated OleDbConnection is busy serving the OleDbDataReader, and no other operations can be performed on the OleDbConnection other than closing it. This is the case until the Close method of the OleDbDataReader is called.


The reader has exclusive access to the connection. I'd cache it in a DataSet, but a second connection would perhaps do the trick also.
 
Share this answer
 
I would imagine, too, that an exception would be thrown by ADO.NET that tells you only one reader can be open on a connection at a time...

Unless you have this wrapped in a try/catch and are eating the exception when it's thrown.
 
Share this answer
 
This got answered yesterday. Each connection can only have one datareader. I didn't realise that, but someone else read the documentation and explained it to you.
 
Share this answer
 

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