用程序关联两个表,为啥表2不显示表1的数据呢?
各位大侠好,小弟正学习delphi,用程序关联两表的内容,现有两个表:表一parts:
partnum description qtylnstock sellingprice
表二items:
itemnum custnum partnum qtysold itempartnum
我现在要用表二的itempartnum字段显示表一的partnum字段的值,程序如下:
unit CItems;
interface
uses
Windows, Messages, Classes, SysUtils, Graphics, Controls, StdCtrls, Forms,
Dialogs, DBCtrls, DB, DBGrids, DBTables, Grids, ExtCtrls;
type
TForm2 = class(TForm)
ItemsTableItemNum: TAutoIncField;
ItemsTableCustNum: TFloatField;
ItemsTablePartNum: TFloatField;
ItemsTableQtySold: TFloatField;
DBGrid1: TDBGrid;
DBNavigator: TDBNavigator;
Panel1: TPanel;
DataSource1: TDataSource;
Panel2: TPanel;
ItemsTable: TTable;
BtnExit: TButton;
PartsTable: TTable;
DataSource2: TDataSource;
DBGrid2: TDBGrid;
PartsTablePartNum: TFloatField;
PartsTableDescription: TStringField;
PartsTableQtyInStock: TFloatField;
PartsTableSellingPrice: TFloatField;
ItemsTableItemPartNum: TStringField;
procedure FormCreate(Sender: TObject);
procedure BtnExitClick(Sender: TObject);
procedure ItemsTableCalcFields(DataSet: TDataSet);
private
{ private declarations }
public
{ public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.FormCreate(Sender: TObject);
begin
ItemsTable.Open;
end;
procedure TForm2.BtnExitClick(Sender: TObject);
begin
Application.Terminate;
end;
procedure TForm2.ItemsTableCalcFields(DataSet: TDataSet);
var
FindResultBoolean:Boolean;
begin
FindResultBoolean:=PartsTable.FindKey([ItemsTablePartNum]);
if FindResultBoolean then
ItemsTableItemPartNum.Value:=PartsTableDescription.Value;
end;
end.
程序运行时报错:
还请高手指点!