#1 2011-12-07 09:40:42

noobies
Member
Registered: 2011-09-13
Posts: 139

how work with dbf files uses OLEDB?

i try connect to sample.dbf,

procedure TForm2.btnADOClick(Sender: TObject);
const
  ADOProvider = 'Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=dBASE IV;Persist Security Info=False;Mode=ReadWrite;Data Source=';
var
  base: string;
begin
  base := 'D:\work\delphi\convbase';
  ADOQuery1.ConnectionString := ADOProvider + base;
  ADOQuery1.SQL.Text := 'select * from sample';
  ADOQuery1.Open;
end;

procedure TForm2.btnSynopseClick(Sender: TObject);
var Props: TOleDBConnectionProperties;
    Conn: TSQLDBConnection;
    Query: TSQLDBStatement;
    F: TFileStream;
begin
  Props := TOleDBMSSQLConnectionProperties.Create('Microsoft.Jet.OLEDB.4.0','D:\work\delphi\convbase','','');
  try
    //Props.ConnectionStringDialogExecute;
    Conn := Props.NewConnection;
    try
      Conn.Connect;
      Query := Conn.NewStatement;
      try
        Query.Execute('select * from sample',true,[]);
        F := TFileStream.Create(ChangeFileExt(paramstr(0),'.json'),fmCreate);
        try
          Query.FetchAllToJSON(F,false);
        finally
          F.Free;
        end;
      finally
        Query.Free;
      end;
    finally
      Conn.Free;
    end;
  finally
    Props.Free;
  end;
end;

but get error
[DBNETLIB][ConnectionOpen (Connect()).]SQL-server not found

i write sample with use ADO, and Synopse http://dl.dropbox.com/u/12662204/convbase.7z

Last edited by noobies (2011-12-07 09:54:11)

Offline

#2 2011-12-07 12:27:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: how work with dbf files uses OLEDB?

Please RTFM. wink

You shall use the generic TOleDBConnectionProperties instead of TOleDBMSSQLConnectionProperties, which is dedicated to MS SQL Server.

Offline

#3 2012-01-10 11:45:26

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: how work with dbf files uses OLEDB?

how display results from query to drawgrid like TSQLTableToGrid?
Simply say as quickly display the JSON array in Drawgrid?

Last edited by noobies (2012-01-10 12:02:36)

Offline

#4 2012-01-10 12:15:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: how work with dbf files uses OLEDB?

Take a look at the DBExplorer sample application.
See e.g. http://synopse.info/fossil/dir?ci=50769 … B+Explorer

You'll find here a way to use a TDrawGrid and display a statement result within.

Offline

Board footer

Powered by FluxBB