使用BDE和Delphi访问dBase文件的好方法是什么? [英] What is a good way of accessing dBase files using BDE and Delphi?

查看:108
本文介绍了使用BDE和Delphi访问dBase文件的好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我必须说我在Delphi方面是个新手,尽管我在十四年前在学校里做了一些Turbo Pascal编程...

First of all, I must state that I'm a complete newb when it comes to Delp although I did some Turbo Pascal programming in school, some fourteen years ago...

我有一个商业的Delphi程序,它使用dBase数据库和BDE来访问它们。我基本上需要将另一个用C#编写的应用程序连接到该数据库,以便能够执行SQL操作,例如选择,插入,更新和删除。

I have a commercial Delphi program which uses dBase database and BDE for accessing them. I basically need to interface another application written in C# to this database, to be able to do SQL operations such as select, insert, update and delete.

不幸的是,使用OLEDB dBase导致索引损坏,只有本地BDE应用程序似乎才能安全地访问数据。

Unfortunately using OLEDB against dBase results in broken indexes, only native BDE apps seem to be able to safely access the data.

通常的想法是创建一个简单的Delphi控制台应用程序,该应用程序可以读取SQL标准输入(Read / ReadLn)中的语句,然后将CSV数据输出到标准输出(WriteLn)。

The general idea was to create a simple Delphi console application which could read SQL statements from standard input (Read/ReadLn) and output CSV data to standard output (WriteLn).

我该怎么做?

我已经使用以下代码成功地使用了简单的TTable访问:

I have successfully gotten simple TTable-access to work, with the following code:

tbl := TTable.Create(nil);

tbl.DatabaseName := 'Exceline';
tbl.TableName := 'KUNDE.DBF';
tbl.Active := True;

WriteLn(tbl.RecordCount);

tbl.Active := False;

是否可以通过执行直接SQL语句来达到相同的目的?

Is there a way I could achieve the same but by executing direct SQL statements instead?

推荐答案

您可以使用TQuery组件执行相同操作:

You can do the same using TQuery component:

qry := TQuery.Create(nil);

qry.DatabaseName := 'Exceline';
qry.SQL.Add('SELECT COUNT(*) AS CNT FROM KUNDE');
qry.Active := True;

WriteLn(qry.FieldByName('CNT').AsString);

qry.Active := False;

这篇关于使用BDE和Delphi访问dBase文件的好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆