delphi - 取消后重用 ADOQuery
问题描述
我在我的 Delphi 2010 应用程序中使用异步 ADO 查询。用户可以请求取消查询,否则可能会因错误而失败。这是我用来取消查询的代码:
if not Assigned(myADOQuery.Recordset) then exit;
if stFetching in myADOQuery.RecordsetState then begin
fCommand := _Command(myADOQuery.Recordset.ActiveCommand);
fCommand.Cancel;
if Assigned(myADOQuery.Recordset) then myADOQuery.Recordset.Cancel;
end;
if Assigned(myADOQuery.Recordset) then myADOQuery.Recordset.Cancel;
StatusBar1.Panels[2].Text := '';
//ShowMessage('Query Cancelled');
myADOQuery.Close;
我正在使用 ADOConnection ExecuteComplete 向用户显示取消(或其他错误):
if EventStatus = esErrorsOccured then ShowMessage(Error.Description);
我现在希望能够在修改后重新使用查询,但是当我重新运行它时,我会收到相同的错误消息。有没有办法可以重置查询(包括 SQL.Text)并再次运行它?
尼穆斯
解决方案
我认为您的问题可能与您的查询的 Connection 对象有关。
AdoConnection 有一个Errors
集合,该集合记录发生的每个 ADO 错误的详细信息。Iirc,此集合作为对象累积,使用 AdoConnection 遇到执行错误,直到您调用Clear
Errors 接口。取消查询执行可能会导致下一次执行出错。
因此,在尝试重新使用您的 AdoQuery 之前尝试以下操作:
myAdoQuery.Connection.Errors.Clear;
让我们知道你的进展情况。
此外,如果我是你,我会在尝试重新打开之前测试 AdoQuery 的 RecordSet 是否为 NIL,并在取消例程结束时将其显式设置为 NIL。以防万一 ...
推荐阅读
- input - 尝试制作 NDI 网络摄像头输入(虚拟输入)的第二个实例
- delphi - 使用 Delphi 的 HTML5 画布动画
- reactjs - 反应条件渲染
- mysql - Mysql - 带有重音符号的 Concat 字符串会导致格式错误的字符
- javascript - Firefox中的D3升高和降低svg元素不起作用
- amazon-web-services - 使用 ARN 创建 aws s3clinet 时出现问题,承担 s3 存储桶的角色
- javascript - 角度导航问题
- c# - 为 Axis2 Web 服务创建客户端时对传输和消息使用不同的证书
- javascript - Vue.js:如何更改 Vue2-slider 组件的颜色
- python - Tensorflow 未在 RTX 3060 Ti 上检测到 GPU