unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
DataSource1: TDataSource;
DataSource2: TDataSource;
RDB_SQL: TRadioButton;
RDB_Access: TRadioButton;
DBGrid1: TDBGrid;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
procedure RDB_SQLClick(Sender: TObject);
procedure RDB_AccessClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
function SelectADO(ADOX:integer):TADOQuery;
{ Public declarations }
end;
var
Form1: TForm1;
DatabaseType:integer;
UseADOQueryX:TADOQuery;
implementation
{$R *.dfm}
{Please remember set the DataSet property for DataSource and set the SQL property for ADOQuery
Use the same name of the database and table
the SQL Server table structure is the same as the Access tables}
function TForm1.SelectADO(ADOX:integer):TADOQuery; //select the ADOQuery
begin
if ADOX=1 then
Result:=ADOQuery1
else
Result:=ADOQuery2;
end;
procedure TForm1.RDB_SQLClick(Sender: TObject);
var
YourServerName:string;
begin
ADOConnection1.Connected:=false;
ADOConnection1.ConnectionString:='';
YourServerName:='MARKING_MA\MARKING_MA';//This my SQL_Server name
ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;'+
'Persist Security Info=False;Initial Catalog=master;'+
'Data Source='+YourServerName;
ADOConnection1.DefaultDatabase:='master';
ADOConnection1.Connected:=true;
DatabaseType:=1;
ADOQuery1.Open;
DBGrid1.DataSource:=DataSource1;
end;
procedure TForm1.RDB_AccessClick(Sender: TObject);
begin
with ADOConnection1 do
begin
Connected:=false;
ConnectionString:='';
ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;'+
'Data Source=Test.mdb;Persist Security Info=False';
DefaultDatabase:='';
Connected:=true;
Provider:='Microsoft.Jet.OLEDB.4.0';
end;
DatabaseType:=2;
ADOQuery2.Open;
DBGrid1.DataSource:=DataSource2;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
UseADOQueryX:=SelectADO(DatabaseType);
with UseADOQueryX do
begin
Append;
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
UseADOQueryX:=SelectADO(DatabaseType);
UseADOQueryX.Post;
end;
end.
Copyright 才子鸣
posted on 2006-06-10 18:53
才子£鸣 阅读(507)
评论(0) 编辑 收藏 引用 所属分类:
精彩文章