Delphi 5.0 通过代码打开Interbase/FireBird连接
这是老东西了!与delphi 5.0和interbase 1.6相关。
我正在尝试通过代码打开数据库连接。但这段代码与启用连接有关,所有组件都是使用delphi拖放用户界面添加的:DataSource1、TForm1、DBGrid、DBNavigator等。
procedure TDataModule2.DataModuleCreate(Sender: TObject);
begin
database.DatabaseName:='C:\MyDatabase.GDB';
database.Connected := true;
database.Open;
IBTransaction.Active := true;
myTable.Open;
end;
我有一个带有DBGrid和DBNavigator组件的TForm。我还有一个 TIBQuery(与 DataSource1 关联),其 SQLString 上包含此代码:
SELECT * FROM NEW_TABLE
在表单上,我有此代码来启用 DBNavigator 和 DBGrid 以显示 DB 值。数据库非常简单,只是一张表:NEW_TABLE 和 VARCHAR 类型的 NEW_VALUE
procedure TForm1.FormCreate(Sender: TObject);
begin
DataSource1.DataSet.Open;
// This will call the query associated to this DataSource1 the tibQuery1 to call
// SELECT * FROM NEW_TABLE, but the message below appears: IBClientError...
end;
消息出现: IBClientError 并显示消息“数据库未分配”
OBS1:如果我在 delphi 用户界面上手动连接组件,则会建立与数据库的连接。
This is old stuff! Is related to delphi 5.0 and interbase 1.6.
I'm trying to open a DB connection via code. But this code is related to enabling the connection, all the components were added using delphi drag-drop User Interface: DataSource1, TForm1, DBGrid, DBNavigator etc..
procedure TDataModule2.DataModuleCreate(Sender: TObject);
begin
database.DatabaseName:='C:\MyDatabase.GDB';
database.Connected := true;
database.Open;
IBTransaction.Active := true;
myTable.Open;
end;
I have a TForm with DBGrid and DBNavigator component. I also have a TIBQuery (that DataSource1 is associated to) with this code on the SQLStrings:
SELECT * FROM NEW_TABLE
On the Form I have this code to enable DBNavigator and DBGrid to show the DB Values. The DB is very simple is just a table: NEW_TABLE with a NEW_VALUE of VARCHAR type
procedure TForm1.FormCreate(Sender: TObject);
begin
DataSource1.DataSet.Open;
// This will call the query associated to this DataSource1 the tibQuery1 to call
// SELECT * FROM NEW_TABLE, but the message below appears: IBClientError...
end;
The message appears:
IBClientError with message 'Database not assigned'
OBS1: If I connect the components by hand on delphi user interface, the connection with the DB is established.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须分配
Database
属性您的查询,例如:You have to assign the
Database
property of your query, something like: