ado连接ms sql server 2000程序

type
TForm1 = class(TForm)
cds: TClientDataSet;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure ExportData(const tableNames: string);
procedure ImportData(const fileName, tableNames: string);
public
{ Public declarations }
end;

function adothread(param: pointer): integer; stdcall;var con, cmd :
variant;begin coinitialize(nil); con := getnewconnection(…); if
varisempty(con) then begin //未连接上,退出 exit; end eles cmd :=
getnewcommand(con) while bterminate do begin if varisempty(con) then
//连接失败 退出 exit else sleep(1000); end; closeconnection(con);
//自定义的关闭函数。 其实测试时, cmd := unassigned; couninitialize;
result := 0;end;

  • values + ‘)’);
    cds.Next;
    end;
    end;
    end;
    sl.SaveToFile(ExtractFilePath(Application.ExeName) + ‘export.sql’);
    sl.Free;
    tables.Free;
    end;

uses untDB;

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Data.DB,
Datasnap.DBClient;

var
Form1: TForm1;

procedure TForm1.ExportData(const tableNames: string);
var
sql, err: string;
sl, tables: TStringList;
i, h: Integer;
fieldNames, values: string;
function GetValue(field: TField): string;
begin
case field.DataType of
ftString, ftTimeStamp:
begin
Result := QuotedStr(field.AsString);
end;
ftBoolean:
begin
case field.AsBoolean of
true: Result := ‘1’;
false: Result := ‘0’;
end;
end;
else
if not VarIsNull(field.Value) then
begin
Result := VarToStr(field.Value);
end
else
Result := ‘null’;
end;
end;

procedure TForm1.ImportData(const fileName, tableNames: string);
var
cmd, tables: TStringList;
err, sql: string;
i: Integer;
begin
if (not FileExists(fileName)) or (tableNames = ”) then
exit;
tables := TStringList.Create;
tables.Delimiter := ‘,’;
tables.DelimitedText := tableNames;
for i := 0 to tables.Count – 1 do
begin
sql := ‘truncate table ‘ + tables[i];
frmDB.ExecuteSQL(sql, err);
end;
tables.Free;

cmd := TStringList.Create;
cmd.LoadFromFile(fileName);
frmDB.ExecuteSQL(cmd.Text, err);
cmd.Free;
end;

Author

发表评论

电子邮件地址不会被公开。 必填项已用*标注