我的毕业设计是一个考试系统。我的数据库中有这样的一张表:
sno(学生学号)    
tleixing(题目类型)
tno(题号)  
tanswer(正确答案)
tjieda(学生做的结果)
tpanduan(是否正确) 
该表中除了tpanduan字段没有值,别的都有值。 
我希望根据学号和题目类型和题号查到一个学生的选择题记录并进行判断是否正确,正确则把tpandaun修改为1,否则为0。
我用的是qurey,pingfen和pingfen1都指向同一张表!
我做了两天仍然没有搞定!急!希望大家帮忙!看看我的程序有什么问题!谢谢先!
procedure TForm12.Button1Click(Sender: TObject);
var i,tno,tpanduan,recno:integer;
var tleixing,sno:string;
begin
tleixing:='选择题';
sno:=edit1.Text;//学生学号;
with dm.pingfen do   //查找是否有该学生考试记录!
     begin
      close;
      sql.Clear;
      sql.Add('select * from test where sno=:q1 and tleixing=:q2');
      params[0].AsString:=sno;
      params[1].AsString:=tleixing;
      execsql;
      open;
      end;
if radiobutton1.Checked then   
  begin
     recno:=dm.pingfen.RecordCount;
     if recno=0 then
     begin
       if application.MessageBox('该考生在考试安排中吗?','提示',mb_okcancel) =mrok then
        application.MessageBox('该考生缺考,成绩作零分计算','提示',mb_ok)
        else
        application.MessageBox('请重新输入考生学号!','提示',mb_ok);
        edit1.Text:='';
        exit;
      end;    for i:=1 to recno do
    begin
       tno:=i;
         if dm.pingfen.FieldByName('tanswer').Value=dm.pingfen.FieldByName('tjieda').Value then
           begin
           tpanduan:=1;
           with dm.pingfen1 do
          begin
           close;
           sql.Clear;
           sql.Add('update  test set tpanduan=:q1 where sno=:q2 and tleixing=:q3 and tno=:q4');
           params[0].AsInteger:=tpanduan;
           params[1].AsString:=sno;
           params[2].AsString:=tleixing;
           params[3].AsInteger:=tno;
           execsql;
          end;
          end
       else
          begin
          tpanduan:=0;
          with dm.pingfen1 do
          begin
           close;
           sql.Clear;
           sql.Add('update  test set tpanduan=:q1 where sno=:q2 and tleixing=:q3 and tno=:q4');
           params[0].AsInteger:=tpanduan;
           params[1].AsString:=sno;
           params[2].AsString:=tleixing;
           params[3].AsInteger:=tno;
           execsql;
          end;
          end;
    dm.pingfen.Next;
    end;
  end;end;

解决方案 »

  1.   

    通过pingfen(query)来查找,pingfen1(query)来修改!希望大家帮忙!
      

  2.   

    procedure TForm12.Button1Click(Sender: TObject);
    var i,tno,tpanduan,recno:integer;
    var tleixing,sno:string;
    begin
    tleixing:='选择题';
    sno:=edit1.Text;//学生学号;
    with dm.pingfen do   //查找是否有该学生考试记录!
         begin
          close;
          sql.Clear;
          sql.Add('select * from test where sno=:q1 and tleixing=:q2');
          params[0].AsString:=sno;
          params[1].AsString:=tleixing;
          //execsql;   <----------------------------错误1
          open;
          end;
    if radiobutton1.Checked then   
      begin
         recno:=dm.pingfen.RecordCount;
         if recno=0 then
         begin
           if application.MessageBox('该考生在考试安排中吗?','提示',mb_okcancel) =mrok then
            application.MessageBox('该考生缺考,成绩作零分计算','提示',mb_ok)
            else
            application.MessageBox('请重新输入考生学号!','提示',mb_ok);
            edit1.Text:='';
            exit;
          end;    for i:=1 to recno do--------------->改为while not dm.pingfen.eof do
        begin
           tno:=i;
             if dm.pingfen.FieldByName('tanswer').Value=dm.pingfen.FieldByName('tjieda').Value then
               begin
               tpanduan:=1;
               with dm.pingfen1 do
              begin
               close;
               sql.Clear;
               sql.Add('update  test set tpanduan=:q1 where sno=:q2 and tleixing=:q3 and tno=:q4');
               params[0].AsInteger:=tpanduan;
               params[1].AsString:=sno;
               params[2].AsString:=tleixing;
               params[3].AsInteger:=tno;
               execsql;
              end;
              end
           else
              begin
              tpanduan:=0;
              with dm.pingfen1 do
              begin
               close;
               sql.Clear;
               sql.Add('update  test set tpanduan=:q1 where sno=:q2 and tleixing=:q3 and tno=:q4');
               params[0].AsInteger:=tpanduan;
               params[1].AsString:=sno;
               params[2].AsString:=tleixing;
               params[3].AsInteger:=tno;
               execsql;
              end;
              end;
        dm.pingfen.Next;
        end;
      end;end;
      

  3.   

    你的表里同时有正确答案和学生答案,那么不用这么复杂,一个语句搞定:'update  test set tpanduan=:True where tjieda=tanswer'tpanduan字段如果是Boolean型则并非没有值,默认是false。
      

  4.   

    在问,在sql server中bit表示boolean吗?
      

  5.   

    to  samcrm(镜花水月),我现在的执行过程是对了,我按步执行的时候能够一步步执行,但是在数据库中的那个列的数据仍然没有得到修改,什么原因?帮忙看看!急!
      

  6.   

    to  samcrm(镜花水月),i表示我在数据库中的选择题的题号,但是在你该的过程中却没有自己加一呀!只能执行一步!for循环可以和while结合使用吗?
      

  7.   

    'update  test set tpanduan=:True where tjieda=tanswer'
    不行么?
      

  8.   

    已经实现!
    procedure TForm12.Button1Click(Sender: TObject);
    var tno,recno:integer;
    var tleixing,sno:string;
    var tpanduan:integer;
    begin
    tleixing:='选择题';
    sno:=edit1.Text;
    with dm.pingfen do
         begin
          close;
          sql.Clear;
          sql.Add('select * from test where sno=:q1 and tleixing=:q2');
          params[0].AsString:=sno;
          params[1].AsString:=tleixing;
          open;
          end;if radiobutton1.Checked then
      begin
         //recno:=select(sno,tleixing);
         recno:=dm.pingfen.RecordCount;
         if recno=0 then
         begin
           if application.MessageBox('该考生在考试安排中吗?','提示',mb_okcancel) =mrok then
            application.MessageBox('该考生缺考,成绩作零分计算','提示',mb_ok)
            else
            application.MessageBox('请重新输入考生学号!','提示',mb_ok);
            edit1.Text:='';
            exit;
          end;        tno:=1;
       while not dm.pingfen.eof do
        begin
               
             if trim(dm.pingfen.FieldByName('tanswer').Value)=trim(dm.pingfen.FieldByName('tjieda').Value) then
               begin
               tpanduan:=1;
               with dm.pingfen1 do
              begin
               close;
               sql.Clear;
               sql.Add('update  test set tpanduan=:q1 where sno=:q2 and tleixing=:q3 and tno=:q4');
               params[0].AsInteger :=tpanduan;
               params[1].AsString:=sno;
               params[2].AsString:=tleixing;
               params[3].AsInteger:=tno;
               execsql;
              end;
              tno:=tno+1;
              end
           else
              begin
              tpanduan:=0;
              with dm.pingfen1 do
              begin
               close;
               sql.Clear;
               sql.Add('update  test set tpanduan=:q1 where sno=:q2 and tleixing=:q3 and tno=:q4');
               params[0].AsInteger :=tpanduan;
               params[1].AsString:=sno;
               params[2].AsString:=tleixing;
               params[3].AsInteger:=tno;
               execsql;
              end;
            tno:=tno+1;
             end;
       
       dm.pingfen.Next;
       
        end;
      end;  end;
     结帐!