result:= true; sSQL:= 'select userid,[审批单号],[用户名],[短信开启],[审批意见],[审批意见nm],[审批状态] from v_shenp where [审批单号]='''+xBillNO+''''; with frmDM.qryDSelect do begin Close; SQL.Clear; SQL.Append(sSQL); Open; if RecordCount > 0 then begin yUserID := FieldByName('userid').AsString; //用户ID yShenpYJ := FieldByName('[审批意见nm]').AsString; //就是这个字段,查询出的值可能是NULL或是有具体的值,但现在如果查询结果是NULL,编译好的程序运行会报错,提示这个字段值找不到
在sql中用isnull,或者数据集中 if Query1.Fields['字段索引'].IsNull then判断
sSQL:= 'select userid,[审批单号],[用户名],[短信开启],[审批意见],isnull([审批意见nm],0),[审批状态] from v_shenp where [审批单号]='''+xBillNO+'''';
if ADOQuery1.FieldByName('name').IsNull then begin // end;
if xxx.value=null then
begin
//
end;
result:= true;
sSQL:= 'select userid,[审批单号],[用户名],[短信开启],[审批意见],[审批意见nm],[审批状态] from v_shenp where [审批单号]='''+xBillNO+'''';
with frmDM.qryDSelect do
begin
Close;
SQL.Clear;
SQL.Append(sSQL);
Open;
if RecordCount > 0 then
begin
yUserID := FieldByName('userid').AsString; //用户ID
yShenpYJ := FieldByName('[审批意见nm]').AsString; //就是这个字段,查询出的值可能是NULL或是有具体的值,但现在如果查询结果是NULL,编译好的程序运行会报错,提示这个字段值找不到
begin
//
end;
FieldByName('[审批意见nm]').AsString 不是会隐性转换为空字符串''嘛???应该是还有别的地方有点问题吧
建议楼主在窗体上放一个DBGrid,显示你查询到的所有数据,看看是否存在“[审批意见nm]”这个字段。