2,507
社区成员




unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;
type
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
con1: TADOConnection;
qry1: TADOQuery;
SourceDress, sConnectionString, sTableName, Sqltext: string;
begin
con1:= TADOConnection.Create(nil);
qry1:= TADOQuery.Create(nil);
SourceDress := ExtractFilePath(Application.ExeName);
sConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+SourceDress+';Extended Properties=dBase III;Persist Security Info=False;';
con1.ConnectionString:= sConnectionString;
con1.Open;
//创建DBF文件
sTableName := 'tbTest' + FormatDateTime('yyyymmddhhmmss',Now);
Sqltext:='create table '+ sTableName + '.dbf' +'(row1 char(6),row2 char(8),row3 char(4))';
qry1.Connection:= con1;
qry1.Close;
qry1.SQL.Clear;
qry1.SQL.Add(SqlText);
qry1.ExecSQL;
//在里面放入一条数据
Sqltext := 'insert into ' + sTableName + '(row1,row2,row3)values(' + QuotedStr('123456') + ',' + QuotedStr('12345678') + ',' + QuotedStr('yy') + ')';
qry1.Close;
qry1.SQL.Clear;
qry1.SQL.Add(Sqltext);
qry1.ExecSQL;
qry1.Free;
con1.Free;
end;
end.
procedure TForm1.Button1Click(Sender: TObject);
begin
with adoquery1 do
begin
CLOSE;
sql.Clear;
sql.Add('CREATE TABLE testtbl (bh char(10),xm char(16),cj number(6,2))');
ExecSql;
close;
close;
end;
adoconnection1.Close;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
s1,s2,s3,s:string;
begin
s1:='Provider=VFPOLEDB.1;Data Source=';
s3:='data;Password="";Collating Sequence=MACHINE';
s2:=ExtractFilePath(Application.ExeName);
s:=s1+s2+s3;
ADOConnection1.ConnectionString :=s;
ADOConnection1.Connected:=true;
end;
我感觉是语法不对!应当使用标准VFP语法。
以上代码在装oledb for vfp(vfp9.0带的或单独下载),原始代码使用d7开发,xe2下面修改,win7 x64下面通过