近来我用Delphi+sql学做系统,连接用的是ADO。调试程序的时候出现了下面的错误,看不懂,请大家给个提示,要如何避免这个错误的出现。
补充一下,这个错误是当我单步运行到数据模块窗体的时候出现的。
debugger exception notification:
project MDIAPP.exe raised exception class EVariantTypeCastError with message'Could not convert variant of type(Null) into type (String)'.
Process stopped.Use Step or Run to continue.
补充一下,这个错误是当我单步运行到数据模块窗体的时候出现的。
debugger exception notification:
project MDIAPP.exe raised exception class EVariantTypeCastError with message'Could not convert variant of type(Null) into type (String)'.
Process stopped.Use Step or Run to continue.
s : String;
begin s := Adoquery1.fields[0].Value;
//当Adoquery1.fields[0].Value的值是null时就会出这种错误end;正确的写法是:
var
s : String;
begin s := Adoquery1.fields[0].asstring;
//给数据库的插入记录时如果字段是非空、主键、外键也要注意同样问题
end;
这是其中的一段重要代码,请帮我看一下:
with DM.CustomerOrder do
begin
close;
// 搜寻该编号的所有定单
CommandText := 'Select * from CustomerOrder where 客户编号=:AA';
Parameters.Items[0].value:= DM.Customer.FieldByName('编号').AsString;
Open;
end;
DM是数据模块窗体.
CustomerOrder和Customer都是TADODataSet组件的name.
CustomerOrder.CommandText:=select *from CustomerOrder.
Customer.CommandText:=select *from CustomerOrder.