如z设为整型,字段aa为空,用z:=table1['zz']时出错(能运行但一点按钮就出错),如何解决(200分)

  • 主题发起人 主题发起人 yangjinrui
  • 开始时间 开始时间
Y

yangjinrui

Unregistered / Unconfirmed
GUEST, unregistred user!
如z设为整型,字段aa为空,用z:=table1['zz']时出错(能运行但一点按钮就出错),
如何解决
 
将AA字段的默认值设为0!
 
他们的类型是不是一样的呢?
如果zz字段为整型,那么默认值本来就是空的吗!
 
if table1['zz'] <> null then
z:=table1['zz']
esle
z:=0;
 
z:=table1['zz'].AsInteger;
 
if table1.FieldValues['zz]=Null then
z:=0
else
z:=table1.FieldValues['zz'];
 
建議使用:
z:=table1.FieldByName('zz').AsInteger; or z:=table1zz.AsInteger;
 
z:=table1.FieldByName('zz').AsInteger 可以
z:=table1[zz].AsInteger 不行
 
同意楼上.另外,不要用=null来判断一个值是否为空,而要用isnull
 
if table1.fieldbyName('zz').IsNULL then
z:=0//再这里写上你需要的值
else
z:=table1.fieldbyName('zz').AsInteger
 
多人接受答案了。
 
建議使用:
z:=table1.FieldByName('zz').AsInteger; or z:=table1zz.AsInteger;
table1zz是字段名稱
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部