**************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