procedure TFldorder.BitBtn3Click(Sender: TObject);
var
   i:integer;
begin
   if not fdata.flagquery.Active then    //这个if语句是要来获取i值
   fdata.flagquery.Active:=true;
  fdata.flagquery.SQL.Clear;
  fdata.flagquery.SQL.Add('select Amount1 from ntflag where (number=:number) and (flagID<>1) and (flagID<>3)');
  fdata.flagquery.Parameters.ParamByName('number').Value:=edit3.Text;
  fdata.flagquery.Open;
 if not fdata.flagquery.IsEmpty then
     i:=fdata.flagquery.fieldbyname('Amount1').AsInteger
  else
     showmessage('目前的查询中无记录!');
   Close;
pagecontrol1.ActivePageIndex:=1;
if not checkecho2(edit1) then
begin
application.MessageBox('请核实该员工信息!','友情提示',mb_ok+mb_iconquestion);
pagecontrol1.ActivePageIndex:=0;
edit1.Clear;
end
else if not checkecho3(edit3) then
begin
application.MessageBox('请核实该单号!','友情提示',mb_ok+mb_iconquestion);
pagecontrol1.ActivePageIndex:=0;
edit8.Clear;
end
else if i<strtoint(edit8.Text) then
begin
application.MessageBox(pchar('您的领单数超出该单未加工的件数,该单只剩 '+IntToStr(i)+' 件!'),'友情提示',mb_ok+mb_iconquestion);
pagecontrol1.ActivePageIndex:=0;
edit8.Text:='';
end
else
begin
fdata.stuffLDquery.Edit;
fdata.stuffLDquery.Append;
fdata.stuffLDquery.FieldByName('Serialnmb').AsString:=edit1.Text;
fdata.stuffLDquery.FieldByName('Stuffname').AsString:=edit2.Text;
fdata.stuffLDquery.FieldByName('Number').AsString:=edit3.Text;
fdata.stuffLDquery.FieldByName('Rankname').AsString:=edit4.Text;
fdata.stuffLDquery.FieldByName('Standard').AsString:=edit5.Text;
fdata.stuffLDquery.FieldByName('Stonekind').AsString:=edit6.Text;
fdata.stuffLDquery.FieldByName('Siglecount2').AsString:=edit7.Text;
fdata.stuffLDquery.FieldByName('Amount2').AsString:=edit8.Text;
fdata.stuffLDquery.FieldByName('Total2').AsString:=edit9.Text;
fdata.stuffLDquery.FieldByName('Lddate').AsString:=edit10.Text;
fdata.stuffLDquery.FieldByName('Fldate').AsString:='';
fdata.stuffLDquery.FieldByName('FlagID').AsString:='2';
fdata.stuffLDquery.FieldByName('Flagname').AsString:='加工中';
fdata.stuffLDquery.FieldByName('Re').AsString:=memo1.Text;
fdata.stuffLDquery.Post;
application.MessageBox('恭喜您,操作成功!','友情提示',mb_ok);
fdata.stuffLDquery.Close;
bitbtn3.Enabled:=false;
bitbtn4.Enabled:=false;
end;fdata.flagquery.Edit;   //更新标志表
fdata.flagquery.SQL.Clear;
fdata.flagquery.FieldByName('Amount1').Value:=i-strtoint(edit8.Text);
fdata.flagquery.FieldByName('flagname').AsString:='部分加工中';
fdata.flagquery.SQL.Add('update ntflag set flagID:=3,flagname,Amount1 where number=:number');
fdata.flagquery.Parameters.ParamByName('number').Value:=edit3.Text;
fdata.flagquery.Open;
fdata.flagquery.Close;
end;
上面那些是我在一个按钮里面进行的操作 ,我想问的我上面的i值获取方法错在哪里呢?
怎么就得不到正确的值呢?而是一直为零哦?
还有一个问题就是最后标志表的更新操作是否正确呢?
表中是有Amount1这个字段但它会提示说找不到这个字段名哦?

请指教

解决方案 »

  1.   

    procedure TFldorder.BitBtn3Click(Sender: TObject);
    var
       i:integer;
    begin
       if not fdata.flagquery.Active then    //这个if语句是要来获取i值
       fdata.flagquery.Active:=true;
      fdata.flagquery.SQL.Clear;
      fdata.flagquery.SQL.Add('select Amount1 from ntflag where (number=:number) and (flagID<>1) and (flagID<>3)');
      fdata.flagquery.Parameters.ParamByName('number').Value:=edit3.Text;
      fdata.flagquery.Open;
     if not fdata.flagquery.IsEmpty then
         i:=fdata.flagquery.fieldbyname('Amount1').AsInteger
      else
         showmessage('目前的查询中无记录!');
       Close;  ///不管fdata.flagquery是否为空值到这里程序都会结束,即下面的语句是没用的。因为close默认的是窗体的关闭事件。你的意思是否应该是:
     if not fdata.flagquery.IsEmpty then
         i:=fdata.flagquery.fieldbyname('Amount1').AsInteger
      else
        begin
         showmessage('目前的查询中无记录!');
         Close;
        end;
      

  2.   

    不知道TFldorder是什么啊!Close也未必是关闭窗体。
      

  3.   

    i值获取方法错在哪里呢?
    怎么就得不到正确的值呢?而是一直为零哦能保证库里的字段的那条记录的值不为0吗?show出来看看
    最后标志表的更新操作是否正确呢?
    update ntflag set flagID:=3,flagname,Amount1 where number=:number
    好象不对吧  更新标志就行了update ntflag set flagID = 3 where number=:number,Amount1,flagname也用更新吗
    表中是有Amount1这个字段但它会提示说找不到这个字段名哦?
    你的query里的静态字段一定没有添加Amount1,添上就ok
      

  4.   

    procedure TFldorder.BitBtn3Click(Sender: TObject);
    var
       i:integer;
    begin
       if not fdata.flagquery.Active then    //这个if语句是要来获取i值
       fdata.flagquery.Active:=true;
      fdata.flagquery.SQL.Clear;
      fdata.flagquery.SQL.Add('select Amount1,FLAGNAME from ntflag where (number=:number) and (flagID<>1) and (flagID<>3)');
      fdata.flagquery.Parameters.ParamByName('number').Value:=edit3.Text;
      fdata.flagquery.Open;
     if not fdata.flagquery.IsEmpty then
         i:=fdata.flagquery.fieldbyname('Amount1').AsInteger
      else
    //******
       begin
    //*******
         showmessage('目前的查询中无记录!');
       Close;//你这是做什么???关闭窗口吗?如果不是就用ABORT;
    //******
       end;
    //*******
    pagecontrol1.ActivePageIndex:=1;
    if not checkecho2(edit1) then
    begin
    application.MessageBox('请核实该员工信息!','友情提示',mb_ok+mb_iconquestion);
    pagecontrol1.ActivePageIndex:=0;
    edit1.Clear;
    ABORT;
    end;
    if not checkecho3(edit3) then
    begin
    application.MessageBox('请核实该单号!','友情提示',mb_ok+mb_iconquestion);
    pagecontrol1.ActivePageIndex:=0;
    edit8.Clear;
    ABORT;
    END;
    if i<strtoint(edit8.Text) then
    begin
    application.MessageBox(pchar('您的领单数超出该单未加工的件数,该单只剩 '+IntToStr(i)+' 件!'),'友情提示',mb_ok+mb_iconquestion);
    pagecontrol1.ActivePageIndex:=0;
    edit8.Text:='';
    ABORT;
    end;
    //fdata.stuffLDquery.Edit;不要这条语句!一下子修改一下子新增的!不就要是新增吗?要这条语句干嘛!
    fdata.stuffLDquery.Append;
    fdata.stuffLDquery.FieldByName('Serialnmb').AsString:=edit1.Text;
    fdata.stuffLDquery.FieldByName('Stuffname').AsString:=edit2.Text;
    fdata.stuffLDquery.FieldByName('Number').AsString:=edit3.Text;
    fdata.stuffLDquery.FieldByName('Rankname').AsString:=edit4.Text;
    fdata.stuffLDquery.FieldByName('Standard').AsString:=edit5.Text;
    fdata.stuffLDquery.FieldByName('Stonekind').AsString:=edit6.Text;
    fdata.stuffLDquery.FieldByName('Siglecount2').AsString:=edit7.Text;
    fdata.stuffLDquery.FieldByName('Amount2').AsString:=edit8.Text;
    fdata.stuffLDquery.FieldByName('Total2').AsString:=edit9.Text;
    fdata.stuffLDquery.FieldByName('Lddate').AsString:=edit10.Text;
    fdata.stuffLDquery.FieldByName('Fldate').AsString:='';
    fdata.stuffLDquery.FieldByName('FlagID').AsString:='2';
    fdata.stuffLDquery.FieldByName('Flagname').AsString:='加工中';
    fdata.stuffLDquery.FieldByName('Re').AsString:=memo1.Text;
    fdata.stuffLDquery.Post;
    application.MessageBox('恭喜您,操作成功!','友情提示',mb_ok);
    fdata.stuffLDquery.Close;
    bitbtn3.Enabled:=false;
    bitbtn4.Enabled:=false;
    {
    此处更新标志列!!!!!!!!!!!!!
    }
    fdata.flagquery.Edit;   //更新标志表
    fdata.flagquery.FieldByName('Amount1').Value:=i-strtoint(edit8.Text);
    fdata.flagquery.FieldByName('flagname').AsString:='部分加工中';
    fdata.flagquery.POST;
    fdata.flagquery.CLOSE;
    fdata.flagquery.SQL.Clear;
    fdata.flagquery.SQL.Add('update ntflag set flagID:=3 where number=:number');
    fdata.flagquery.Parameters.ParamByName('number').Value:=edit3.Text;
    //上面两条语句可合并为:fdata.flagquery.SQL.Add('update ntflag set flagID:=3 where number='+#39+EDIT3.TEXT+#39);
    //fdata.flagquery.Open;
    fdata.flagquery.EXECSQL;
    fdata.flagquery.Close;
    end;
    怎么代码写这么烂啊!仔细看看我上面给你改的!
    IF... ELSE IF  语句你还是少用吧!弄得你头都大!代码多的时候不要用这东西!太难找到语句的结束点!
      

  5.   

    TO : miky(miky)
    那个CLOSE是我没写完成,我是要关闭QUERY的,其中你说的那个是一个窗体。
    可以加下QQ指教么?
      

  6.   

    到数据库中执行语句:
    select Amount1 from ntflag where (number=:number) and (flagID<>1) and (flagID<>3)
    看是否为多条记录,应该是返回了多条,没有取到正确的值。
      

  7.   

    if not fdata.flagquery.Active then     //更新标志表
    fdata.flagquery.Active:=true;
    fdata.flagquery.SQL.Clear;
    fdata.flagquery.SQL.Add('select * from ntflag where number=:number');
    fdata.flagquery.Parameters.ParamByName('number').Value:=edit3.Text;
    fdata.flagquery.Open;
    fdata.flagquery.FieldByName('Amount1').Value:=i-strtoint(edit8.Text);
    fdata.flagquery.FieldByName('flagname').AsString:='部分加工中';
    fdata.flagquery.Close;
    fdata.flagquery.SQL.Clear;
    fdata.flagquery.SQL.Add('update ntflag set flagID:=3,flagname,Amount1 where number=:number');
    fdata.flagquery.Parameters.ParamByName('number').Value:=edit3.Text;
    fdata.flagquery.Open;
    fdata.flagquery.Close;我用上面的方法来更新数据表可以么?
      

  8.   

    TO lcl99(刘帆) 
    我是要更新这个QUERY对应的表
    呵呵 ```
    我把最新值放在上面````
      

  9.   

    ?????
    'update ntflag set flagID:=3 where number=:number'
    flagID后面要‘:’吗?这里用得是什么数据库?
      

  10.   

    ?????
    'update ntflag set flagID:=3 where number=:number'
    flagID后面要‘:’吗?这里用得是什么数据库?
    回答是不要!
    用的是MS_SQL
      

  11.   

    我给你的语句中有一条要改!COPY的你的!//上面两条语句可合并为:fdata.flagquery.SQL.Add('update ntflag set flagID=3 where number='+#39+EDIT3.TEXT+#39);set flagID:=3 是错误的! 应该是:set flagID=3