这算什么?------access当值为空的时候竟然出错!(100分)

  • 主题发起人 !雅龙
  • 开始时间

!雅龙

Unregistered / Unconfirmed
GUEST, unregistred user!
声明:该字段已经设置可以为空

AConnection := CreateOleObject('ADODB.Connection');
AConnection.Open('Driver={Microsoft Access Driver (*.mdb)};DBQ=' + ExtractFilePath(Paramstr(0)) + 'xxx.mdb');
ARecordSet := CreateOleObject('ADODB.RecordSet');
ARecordSet.open('SELECT * FROM 客户',AConnection,3,1,0001);

while not ARecordSet.eof do
begin
SHOWMESSAGE(ARecordSet.Fields['城市'].value);
END;

........


谁会想到当字段(‘城市’)为空值的时候会出现什么问题?

那就是错误!!!----“Invalid variant type conversion”

我觉得简直荒唐!我知道在一些大型数据库中,可以用AsString来代替Value,但我用的是Access,不行!

 
function MsgBox(Msg:Variant;Title:string='';Flag:longint=0):integer;
//简化MessageBox函数
begin
if length(title)=0 then title:=SAppName;
if flag=0 then flag:=MB_OK + MB_ICONINFORMATION;
Result:=application.MessageBox(pchar(vartostr(Msg)),pchar(Title),flag);
end;
再把
SHOWMESSAGE(ARecordSet.Fields['城市'].value);
改成
MsgBox(ARecordSet.Fields['城市'].value);
 
if ARecordSet.Fields['城市'].value=null then ShowMessage('')
else showmessage9ARecordSet.Fields['城市'].value)
 
多人接受答案了。
 
顶部