例子://根据SQL取得数据function TDBService.GetData(aSQL: widestring; out ErrMsg:OleVariant):OleVariant;var Data:TADODataSet; dspData:TDataSetProvider; tmpData:OleVariant;begin ErrMsg:=''; result:=tmpData; if aSQL<>'' then begin Data:=TADODataSet.Create(nil); Data.Connection:=ADOConnection1; dspData:=TDataSetProvider.Create(nil); dspData.DataSet:=Data; try Data.Close; Data.CommandText:=aSQL; try Data.Open; result:=dspData.Data; except on e: EOleException do begin if e.ErrorCode = -2147467259 then //数据库中断时返回的错误代号 begin //重新连接数据库 ADOConnection1.Close; ADOConnection1.Open; end; ErrMsg:=e.Message+#13+aSQL; end; on e: EDatabaseError do ErrMsg:=e.Message+#13+aSQL; end; finally FreeAndNil(Data); FreeAndNil(dspData); end; end;end;