急!Ado的filter后出现的问题!(50分)

  • 主题发起人 主题发起人 kiminsun
  • 开始时间 开始时间
K

kiminsun

Unregistered / Unconfirmed
GUEST, unregistred user!
在 adotable中,我设置了一个filter ,如 " IsValid ='1' &nbsp;",当我对dataset处理时,<br>我需修改IsValid字段,当dataset (经过filter 后)中只有一条记录时,我执行<br>adotable.edit;<br>adotable.fieldvalues['IsValid'] ='0';<br>adotable.post;<br>会产生一个异常:<br>"BOF 或 EOF 中有一个是"真",或者当前的记录已被删除,所需的操作要求一个当前的记录。"<br>但记录实际已修改。 &nbsp;<br><br>看了以前的帖子说是ADO的Bug,要打ADO的补丁。<br>但我的是Delphi 7.3.1.3,mdac2.8的,都是新的,为什么也会出现这样的问题。<br><br>但如果我直接运行编译好的exe文件的话不会出异常。<br>小弟刚学Delphi不久,请各位高手解答一下,谢谢!
 
你干吗 不用 <br>query <br>用 select * from tablde where IsValid ='1' <br>一样 可以 post<br><br>改成 <br>ADOTable1.DisableControls;<br>ADOTable1.Filtered:=false;<br><br>dotable.edit;<br>adotable.fieldvalues['IsValid'] ='0';<br>adotable.post;<br><br><br>ADOTable1.Filtered:=True;<br>ADOTable1.EnableControls;
 
没事儿,BUG,调试环境中会出现这种问题,但能通过编译后的EXE是没问题的
 
type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; DataSource1: TDataSource;<br>&nbsp; &nbsp; dbgrd1: TDBGrid;<br>&nbsp; &nbsp; ADOTable1: TADOTable;<br>&nbsp; &nbsp; btn1: TButton;<br>&nbsp; &nbsp; ADOQuery1: TADOQuery;<br>&nbsp; &nbsp; procedure btn1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormShow(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br>procedure TForm1.btn1Click(Sender: TObject);<br>begin<br>&nbsp; {if adotable1.RecordCount =1 then<br>&nbsp; begin<br>&nbsp; &nbsp; adotable1.DisableControls;<br>&nbsp; &nbsp; adotable1.Filtered:=false;<br><br>&nbsp; &nbsp; adotable1.edit;<br>&nbsp; &nbsp; adotable1.FieldByName('IsValid').AsString := '0';<br>&nbsp; &nbsp; adotable1.post;<br><br>&nbsp; &nbsp; adotable1.Filtered:=True;<br>&nbsp; &nbsp; adotable1.EnableControls;<br>&nbsp; end<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; adotable1.Edit;<br>&nbsp; &nbsp; adotable1.FieldByName('IsValid').AsString := '0';<br>&nbsp; &nbsp; adotable1.Post;<br>&nbsp; end; &nbsp; }<br>&nbsp; adoquery1.Edit;<br>&nbsp; adoquery1.FieldByName('IsValid').AsString := '0';<br>&nbsp; adoquery1.Post;<br>end;<br><br>procedure TForm1.FormShow(Sender: TObject);<br>begin<br>&nbsp; adoquery1.Close;<br>&nbsp; adoquery1.SQL.Text := 'select * from DDepartment where IsValid = ''1''';<br>&nbsp; adoquery1.Open;<br>end;<br><br>adoquery1和adotable1的filter预先写好:IsValid =1 <br>两个都试了都会出问题<br><br>to hfghfghfg:<br>我用了adoquery和你写的,当表中有多个数据时正常,但在修改表中最后一个数据的时候就会出错。
 
那就 补丁了
 
后退
顶部