献出所有分!!请问用ADO怎么样不通过ODBC连接.DBF表????(100分)

  • 主题发起人 主题发起人 be_there
  • 开始时间 开始时间
B

be_there

Unregistered / Unconfirmed
GUEST, unregistred user!
可以用ado嘛!
 
奇怪你是怎么用ado通过odbc连接dbf的?
ado 有个 connectingstring,选中然后用connectionstring builder建立
联接字符串就可以了,默认是不通过odbc的
 
对DBF的访问是指定一个目录:
然后在“所有”页中编辑“Extended Properties”
在[属性值]中填入
"dBASE III"或"dBASE IV"或"dBASE 5.0"
然后使用TADOTable中的Table Name中找到你的数据库,OK!
 
var myaccess:string;
const mystr1='provider=%s;data provider=%s;data source=%s';
myprovider='msdatashape.1';
mydataprovider='microsoft.jet.oledb.4.0';
begin
myaccess:=extractfilepath(application.ExeName)+'database.mdb'; //指定文件名称
adoconnection1.Connected:=false;
adoconnection1.ConnectionString:=format(mystr1,[myprovider,mydataprovider,myaccess]);
adoconnection1.Connected:=true;
adotable1.Close;
adotable1.TableName:='tablename';
adotable1.Open;
动态连接当前目录下的数据库
 
procedure TForm1.Button1Click(Sender: TObject);
var
DBPath: String;
begin
DBPath:='e:/dfwtest/test7';//你的数据库路径目录;
ADOConnection1.ConnectionString:='Provider=MSDASQL.1;'
+'Persist Security Info=False;'
+'Extended Properties='
+'"Driver={Microsoft Visual FoxPro Driver};'
+'UID=;'
+'SourceDB='+ DBPath + ';'
+'SourceType=DBF;'
+'Exclusive=No;'
+'BackgroundFetch=Yes;'
+'Collate=Machine;'
+'Null=Yes;'
+'Deleted=Yes;"';
AdoConnection1.Open;
AdoQuery1.Sql.Text := 'create table "aaa.dbf" (aaa char(2))';
//AdoQuery1.Sql.Text := 'create table "ddd.dbf" (aaa char(2)),fff float(3),eee numeric (4,1),torf boolean ,rdate date)';
AdoQuery1.ExecSql;
end;
//ado打开dbf
procedure TForm1.Button3Click(Sender: TObject);
var
DBPath: String;
begin
DBPath:='e:/dfwtest/test7';//你的数据库路径;
ADOConnection1.ConnectionString:='Provider=MSDASQL.1;'
+'Persist Security Info=False;'
+'Extended Properties='
+'"Driver={Microsoft Visual FoxPro Driver};'
+'UID=;'
+'SourceDB='+ DBPath + ';'
+'SourceType=DBF;'
+'Exclusive=No;'
+'BackgroundFetch=Yes;'
+'Collate=Machine;'
+'Null=Yes;'
+'Deleted=Yes;"';
AdoQuery1.close;
AdoQuery1.sql.clear;
AdoQuery1.sql.Text := 'select * from ddd.dbf';
adoquery1.Open;
end;
 

Similar threads

后退
顶部