if trim(AdoQuery1.FieldByName('f1').AsString)='' then V1:='';
if trim(AdoQuery1.FieldByName('f1').AsString)='' then V1:='0';
我用下面代码做的测试,表中字段分别为guojia ,she,shi,都是整形,我只添加了guojia的代码,读取shi的时候,不报错,读的就是空 procedure TForm1.Button2Click(Sender: TObject); var s : string; begin with ADOTable1 do begin if not Active then Open; Insert; FieldByName('guojia').Value := 7; Post; end; adotable1.Open; if ADOTable1.Locate('guojia',7,[loCaseInsensitive]) then s:=ADOTable1.FieldByName('shi').AsString; showmessage(s); end;
自已写个函数嘛`~`function TForm1.NulltoZore(s: string): string; begin if trim(s)='' then Result :='0' else Result:=s; end;procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(NulltoZore(edit1.text)); end;
procedure TForm1.Button2Click(Sender: TObject);
var
s : string;
begin
with ADOTable1 do
begin
if not Active then Open;
Insert;
FieldByName('guojia').Value := 7;
Post;
end;
adotable1.Open;
if ADOTable1.Locate('guojia',7,[loCaseInsensitive]) then s:=ADOTable1.FieldByName('shi').AsString;
showmessage(s);
end;
begin
if trim(s)='' then
Result :='0'
else
Result:=s;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(NulltoZore(edit1.text));
end;