标题:用程序关联两个表,为啥表2不显示表1的数据呢?
只看楼主
handsun01
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2009-8-1
结帖率:0
 问题点数:0 回复次数:1 
用程序关联两个表,为啥表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.
程序运行时报错:

还请高手指点!
搜索更多相关主题的帖子: 数据 
2009-09-06 00:34
handsun01
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2009-8-1
得分:0 
问题已解决
2009-09-06 00:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-284931-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.113085 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved