MS访问问题 [英] MS Access Problem

查看:99
本文介绍了MS访问问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码,问题是第二个阅读器,即ReadGroup
读取数据失败

代码:-


here is the code and the problem is that the second reader i.e ReadGroup
Fail to read data

code:-


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 ";




而(DataReader.Read())
{

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


字符串str1 =从组中选择*,其中Tab_ID =" + TabID;
OleDbCommand CmdGroup =新的OleDbCommand(str1,connst);
OleDbDataReader ReadGroup = CmdGroup.ExecuteReader();
ReadGroup.Read();
Console.WriteLine(ReadGroup.HasRows);


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

//for(int k = j; k< = i; k ++)
//{
字符串str2 =从Group_id = 0的项目中选择*";
OleDbCommand CmdControls =新的OleDbCommand(str2,connst);
OleDbDataReader ReadControl = cmd.ExecuteReader();
而(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());

}
}
//}
}




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());

}
}
//}
}

推荐答案

在使用OleDbDataReader时,关联的OleDbConnection忙于为OleDbDataReader提供服务,并且无法执行其他任何操作在OleDbConnection上,而不是将其关闭.在调用OleDbDataReader的Close方法之前,情况就是这样.

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.



读者拥有对该连接的独占访问权.我会将其缓存在DataSet中,但是第二个连接也许也可以解决问题.



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.


我也可以想象,ADO.NET会抛出一个异常,该异常表明您一次只能在一个连接上打开一个阅读器...

除非您将它包装在try/catch中,并且在抛出异常时正在吃异常.
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.


这个问题昨天得到了回答.每个连接只能有一个数据读取器.我没有意识到,但是其他人阅读了文档并向您解释了.
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.


这篇关于MS访问问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆