ADO连接MDB数据库的同步问题。。。。送分(100分)

O

otqsoft

Unregistered / Unconfirmed
GUEST, unregistred user!
前段时间写了一个程序,配置数据存在放在本地Acces数据库中,遇到一个很奇怪的问题,下面是事例代码<br>var<br>&nbsp; tSql: &nbsp; string;<br>&nbsp; Query: &nbsp;TADOQuery;<br>begin<br>&nbsp; Query:= TADOQuery.Create(nil);<br>&nbsp; Query.Connection:= ADOLink; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//定义的一个ADO全局变量<br>&nbsp; tSql:= &nbsp;'select * from menu_system where m_flag=1';<br>&nbsp; Query.Sql.Text:= tSql; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//设置段点1<br>&nbsp; Query.Open; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //设置段点2<br>&nbsp; if Query.Active then<br>&nbsp; begin<br>&nbsp; &nbsp; showmessage(inttostr(Query.RecordCount)); &nbsp;<br>&nbsp; end;<br>end;<br><br>&nbsp; &nbsp;问题: <br>&nbsp; &nbsp; &nbsp; 1. 如果段点放在“设置段点1”处,F8单步执行,RecordCount &gt; 0<br>&nbsp; &nbsp; &nbsp; 2. 如果段点放在“设置段点2”处,F8单步执行,RecordCount = 0<br><br>&nbsp; &nbsp;不知道为什么,是不是ACCESS有什么地方需要设置???
 
怀疑RP出了问题。
 
用查询记录的SQL语句吧,RecordCount有时还有-1的记录呢
 
方法1:<br>select count(*) as cou from menu_system where m_flag=1<br>//<br>Adoquery.fieldbyname('cou').asinteger<br>方法2:<br>Query:= TADOQuery.Create(nil);<br>&nbsp; Query.Connection:= ADOLink; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//定义的一个ADO全局变量<br>if not ADOLink.connected then ADOLink.open;<br>Query,sql.clear;<br>&nbsp; tSql:= &nbsp;'select * from menu_system where m_flag=1';<br>&nbsp; Query.Sql.Text:= tSql; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//设置段点1<br>&nbsp; Query.Open; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //设置段点2<br>&nbsp; &nbsp; showmessage(inttostr(Query.RecordCount)); &nbsp;<br>Query.free;
 
呵呵,谢谢啊<br>我的目的不只是为了取得记录个数,而得到记录集之后,要根据数据动态创建一些东西,而<br>当RecordCount=0时,一些对象就不能创建了。。。<br><br>这个问题是不是和ACCESS的设置有关啊,比如设置独占方式打开。。<br>我今天设置了以独占方式打开,但是还有这个问题,以前用VB的时候,用DAO连接MDB好像也没有遇到类似的问题啊<br><br>郁闷中。。。。 [:(][:(]
 
测试完好<br>或许RP真的出现啥问题了<br>呵呵,开玩笑,楼主别介意啊<br>关注
 
ADOLink.connected:= False;<br>ADOLink.connected:= True;<br><br>每次引用的时候,这样处理一下,出现的机率就小多了,天啊,可是总不能这样搞吧!<br>我用的ADO的版本是2.8的,应该不用升级吧<br>今天打开ACCESS看了一哈,在“工具”-“选项”-“高级”里面有一些参数设置,像什么刷新间隔时间设定,打开方式等。<br>试了几哈,不起作用。。。[:(][:(]
 
两个建议:<br>1、ADO 的 RecordCount 属性仅仅支持静态游标和键集游标;<br>2、使用 RecordCount 时游标位置尽量使用 clUseClient;<br>你的程序改成下面试试:<br>var<br>&nbsp; tSql: string;<br>&nbsp; Query: TADOQuery;<br>&nbsp; cnn: TADOConnection;<br>begin<br>&nbsp; Query := TADOQuery.Create(nil);<br>&nbsp; Query.Connection := ADOLink;<br>&nbsp; Query.CursorLocation := clUseClient; //或者把 ADOLink 设成 ADOLink.CursorLocation := clUseClient,这样就不用每个 Query 都写一次了<br>&nbsp; Query.CursorType := ctStatic;<br>&nbsp; tSql := 'select * from menu_system where m_flag=1';<br>&nbsp; Query.Sql.Text := tSql;<br>&nbsp; Query.Open;<br>&nbsp; if Query.Active then<br>&nbsp; begin<br>&nbsp; &nbsp; showmessage(inttostr(Query.RecordCount));<br>&nbsp; end;<br>end;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
724
import
I
顶部