yUserID    := FieldByName('userid').AsString;  //用户ID
          yShenpYJ    := FieldByName('[审批意见nm]').AsString;  //审批意见nmyShenpYj 这个值可能是数字,也可能是NULL,现在我的这种写法,会导致当这个字段值是NULL时,程序报错,要处何处理啊

解决方案 »

  1.   

    最直接的方法:
    yUserID := VarToStrDef(FieldByName('UserID').Value, '');
      

  2.   

    但问题是记录有可能是NULL,并且我需要根据这个字段值进行判断,如果字段内容为NULL,那么我如何,如果不为NULL 我要如何
      

  3.   


    if ADOQuery1.FieldByName('userid').IsNull then
    beginend;
      

  4.   

     begin // 我加的 
              yUserID    := FieldByName('userid').AsString;  //用户ID
              yShenpYJ    := FieldByName('[审批意见nm]').AsString;  //审批意见nm
              //yShenpYJ := VarToStrDef(FieldByName('[审批意见nm]').Value, '');
              begin
                  sSQL:= 'Select [用户名],[手机号码] from t_userlogin where id=(select [通知领导] from canshu where id ='''+yShenpYJ+''')';
                  with frmDM.qryDSelect do
                  begin
                    Close;
                    SQL.Clear;
                    SQL.Append(sSQL);
                      Open;
                      if RecordCount > 0 then 
                        if  not  FieldByName('[审批意见nm]').IsNull then
                            begin 
    .......................
      

  5.   

    if not FieldByName('[审批意见nm]').IsNull then ...
    else  ...