DBGridEh 的问题(50分)

  • 主题发起人 主题发起人 cgp
  • 开始时间 开始时间
C

cgp

Unregistered / Unconfirmed
GUEST, unregistred user!
我用DBGridEh 显示一个表的数据,修改之后。显示另一个表的数据,在修改数据时经常报错。
就是修改DBGridEh.DataSource;是DBGridEh2.5
 
我用DBGridEh 显示一个表的数据,修改之后。显示另一个表的数据,在修改数据时经常报错。
就是通过修改DBGridEh.DataSource分别显示其它表的数据并修改;是DBGridEh2.5。而同样的
操作改用DBGrid就没有问题。在下请各位用过DBGridEhr的指点。
 
看看你的代码
 
应该没有问题的,将你的代码放出来看看
 
没问题,我试了一下
可能是你的代码有问题吧?
 
要先断开原来的datasource,再连接另外一个
 
是不是你设置了displayformat,不同表的不同字段用同一个displayformat可能会有问题
(当数据类型不同时)
 
是在DBGridEh.Columns中添加了内容吧,清空里边面的列表试一试。
 
**************Student 表*************

object StudentTblID: TAutoIncField
DisplayLabel = '编号'
FieldName = 'ID'
Origin = 'Student.ID'
Required = True
end
object StudentTblNo: TStringField
DisplayLabel = '序号'
FieldKind = fkCalculated

*******
{只是在表的OnCalcFields取得记录的记录号 StudentTblNo.Value:=IntToStr(StudentTbl.RecNo);}
*******

FieldName = 'No'
Size = 5
Calculated = True
end
object StudentTblName: TStringField
DisplayLabel = '姓名'
DisplayWidth = 10
FieldName = 'Name'
Origin = 'Student.Name'
end
object StudentTblSex: TStringField
DisplayLabel = '性别'
FieldName = 'Sex'
Origin = 'Student.Sex'
Size = 2
end
object StudentTblBirthDay: TDateField
DisplayLabel = '出生日期'
FieldName = 'BirthDay'
Origin = 'Student.BirthDay'
DisplayFormat = 'yyyy/mm/dd'
EditMask = '!9999/99/00;1;_'
end
object StudentTblNative: TStringField
AutoGenerateValue = arDefault
DisplayLabel = '民族'
FieldName = 'Native'
Origin = 'Student.Native'
Size = 10
end
object StudentTblClassID: TIntegerField
DisplayLabel = '班级编号'
FieldName = 'ClassID'
KeyFields = 'ClassID'
Origin = 'Student.ClassID'
end
object StudentTblClass: TStringField
DisplayLabel = '班级'
FieldKind = fkLookup
FieldName = 'Class'
LookupDataSet = ClassTbl
LookupKeyFields = 'ID'
LookupResultField = 'ClassName'
KeyFields = 'ClassID'
Lookup = True
end
object StudentTblTeacher: TStringField
DisplayLabel = '教师姓名'
DisplayWidth = 10
FieldKind = fkLookup
FieldName = 'Teacher'
LookupDataSet = ClassTbl
LookupKeyFields = 'ID'
LookupResultField = 'Teacher'
KeyFields = 'ClassID'
ReadOnly = True
Lookup = True
end
object StudentTblPhoto: TGraphicField
DisplayLabel = '相片'
FieldName = 'Photo'
Origin = 'Student.Photo'
BlobType = ftGraphic
end
object StudentTblMemory: TMemoField
DisplayLabel = '备注'
FieldName = 'Memory'
Origin = 'Student.Memory'
BlobType = ftMemo
end
object StudentTblParantsName: TStringField
DisplayLabel = '家长姓名'
DisplayWidth = 10
FieldName = 'ParantsName'
Origin = 'Student.ParantsName'
end
object StudentTblPhone: TStringField
DisplayLabel = '联系电话'
FieldName = 'Phone'
Origin = 'Student.Phone'
end

索引字段:ID,ClassID,Name,parantsName,sex,Phone

******Teacher表******

object TeacherTblID: TAutoIncField
DisplayLabel = '编号'
FieldName = 'ID'
Origin = 'Teacher.ID'
Required = True
end
object TeacherTblName: TStringField
DisplayLabel = '姓名'
FieldName = 'Name'
Origin = 'Teacher.Name'
end
object TeacherTblSex: TStringField
DisplayLabel = '性别'
FieldName = 'Sex'
Origin = 'Teacher.Sex'
Size = 2
end
object TeacherTblBirthDay: TDateField
DisplayLabel = '出生日期'
FieldName = 'BirthDay'
Origin = 'Teacher.BirthDay'
DisplayFormat = 'yyyy/mm/dd'
EditMask = '!9999/99/00;1;_'
end
object TeacherTblNative: TStringField
DisplayLabel = '民族'
FieldName = 'Native'
Origin = 'Teacher.Native'
Size = 10
end
object TeacherTblPhone: TStringField
DisplayLabel = '联系电话'
FieldName = 'Phone'
Origin = 'Teacher.Phone'
end
object TeacherTblPhoto: TGraphicField
DisplayLabel = '相片'
FieldName = 'Photo'
Origin = 'Teacher.Photo'
BlobType = ftGraphic
end
object TeacherTblMemory: TMemoField
DisplayLabel = '备注'
FieldName = 'Memory'
Origin = 'Teacher.Memory'
BlobType = ftMemo
end

索引 ID,Name

*******Class表*********

object ClassTblID: TSmallintField
DisplayLabel = '编号'
FieldName = 'ID'
Origin = 'Class.ID'
Required = True
end
object ClassTblClassName: TStringField
DisplayLabel = '班级名称'
FieldName = 'ClassName'
Origin = 'Class.ClassName'
end
object ClassTblTeacherID: TIntegerField
DisplayLabel = '教师编号'
FieldName = 'TeacherID'
Origin = 'Class.TeacherID'
end
object ClassTblTeacher: TStringField
DisplayLabel = '教师姓名'
FieldKind = fkLookup
FieldName = 'Teacher'
LookupDataSet = TeacherTbl
LookupKeyFields = 'ID'
LookupResultField = 'Name'
KeyFields = 'TeacherID'
Lookup = True
end
object ClassTblFeeMonth: TCurrencyField
DisplayLabel = '每月学费'
FieldName = 'FeeMonth'
Origin = 'Class.FeeMonth'
end
object ClassTblFileName: TStringField
FieldName = 'FileName'
Origin = 'Class.FileName'
end

索引 ID,ClassName

********************************
以上是表的物理字段和查找字段

在主窗体上放一个DBNavigator1 和 DBGridEH1 、
DataSource1、DAISAMDataBase1,Button1,Button2,Button3控件.
DBGridEH1的 DataSource为DataSource1, DataSource1的DataSet指向Student表
这样在DBGridEH1 中显示表Student的数据,修改后移到另外的记录,
然后点击Button1或Button2,Button3.分别修改数据后,移到另外的记录。
几次反复后就会报错。尤其是修改日期字段。在用键盘修改不用鼠标时不报错。

Button1.onClick的代码是

begin
DBGridEh1.Columns.Clear;
DataSource1.DataSet:=ClassTbl;
end;

Button2,Button3的代码与Button1的相似,只是表控件名为另两个。对DBGridEH1
只是设置的DataSource属性,其它默认。

另外我的数据库是DBISAMTb 3.1 for Delphi 5
 
修改DBGridEH1的 DataSource屬性時先將DBGridEH1的 DataSource:=nil,
再進行轉移
 
后退
顶部