PS。。给你个代码看看就知道了。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComObj, Grids, DBGrids, Db, ADODB,Adoint;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Ado1: TADODataSet;
procedure FormCreate(Sender: TObject);
private
adc:Connection; { Private declarations }
adr: Recordset;
function GetRs:IDispatch;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
localrs:RecordSet;
begin
localrs:=Self.GetRs As RecordSet;
Ado1.Recordset:=localRs;
end;
function TForm1.GetRs: IDispatch;
var
str_con: string;
ssql: string;
begin
ssql := 'select * from T_Person_Resume';
str_con := 'Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=wygl;Data Source=fors';
adc:=coConnection.Create;
Adc.Open(str_con, 'sa', '',adConnectUnspecified);
Adr:=CreateComObject(CLASS_Recordset) as Recordset;
Adr.CursorLocation := adUseClient;
Adr.Open(ssql, Adc, AdOpenForwardOnly, AdLockReadOnly, adCmdText);
Result:=Adr;
end;