//将文本文件所在目录作为数据库,其下所有文本文件则被认为是数据库中的表//用逗号分割的几个字符串作为各个字段//查询test.txt,sql语句应该写为,例如:Select * from test#txt procedure TForm1.Button1Click(Sender: TObject);
var
FilePath,FileName,FileDir:String;
//FileText:textfile;
StrList:TStringList;
StrTemp:STring;
j:integer;
begin
if OpenDialog.Execute then
begin
//ExtractFileDir 分离根目录
//ExtractFileExt 分离文件扩展名
//ExtractFileName 分离文件名
//ExtractFilePath 分离文件路径
FilePath := OpenDialog.FileName; //取得文件路径
FileName := ExtractFileName(FilePath); //取得文件名
FileDir:=ExtractFileDir(FilePath); //得到目录名
//AssignFile(FileText, FilePath); //将文件变量与文件关联
//Reset(FileText); //以读写方式打开类型文件和无类型文件
StrList := TStringList.Create;
try
StrList.LoadFromFile(OpenDialog.FileName);
StrTemp := StrList.Text;
StrList.Text := StringReplace(StrTemp,';', ',', [rfReplaceAll]);
StrList.SaveToFile(FileDir+'\111.txt');
finally
StrList.Free;
end;
end;
ADODataSet.Active:=False;
Connection.Close;
Connection.ConnectionString:=
' Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source= '
+FileDir
+';Mode=Share Deny None;Extended Properties=text;Jet OLEDB:System database=""; '
+'Jet OLEDB:Registry Path="";Jet OLEDB:Database Password="";'
+'Jet OLEDB:Engine Type=96;Jet OLEDB:Database Locking Mode=0;'
+'Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;'
+'Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;'
+'Jet OLEDB:Encrypt Database=False;Jet OLEDB:'
+'Don+'''
+'t Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False';
ADODataSet.CommandText:='select Event from '+' 111#txt';
ADODataSet.Active:=true;
end;