我在Delphi 2010应用程序中使用Asynchrounous 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)并再次运行它?
NiMuSi
我认为您的问题可能出在查询的Connection对象上。
AdoConnection具有Errors
集合,该集合记录发生的每个ADO错误的详细信息。 Iirc,此集合在使用AdoConnection的对象中累积遇到执行错误,直到您在Errors接口上调用Clear
。可能是取消查询执行导致下一次执行错误。
因此,在尝试重新使用AdoQuery之前,请尝试以下操作:
myAdoQuery.Connection.Errors.Clear;
并告诉我们您的情况。
[此外,如果您是我,我会在尝试重新打开AdoQuery的RecordSet之前将其测试为NIL,并在取消例程结束时将其显式设置为NIL。以防万一...