我的毕业设计是一个考试系统。我的数据库中有这样的一张表:
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;
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;
解决方案 »
- 如何用资源管理器打开并选中文件,像网际快车、迅雷那样。
- 关于还原数据库备份文件的问题。
- 大家一起讨论一下在Delphi中如何提高数据库查询速度?
- 实际课题碰到的问题。有兴趣的请进来计论好吗?
- 为什么我的代码执行后,插入记录老是不稳定,问题出在哪?
- 因为毕业答辩 急需各位高手滴帮助 有谁愿意帮我完成一个关于超市销售商品的界面呢 拜托!偶是菜鸟 万分感谢
- 共享软件免费赠送(信息仓库个人版)
- Delphi中可以动态建立控件吗?来的都有分
- 我使用的delphi7中 tidhttp 类型不识别怎么办?
- 小女子请问:从excel导入word文档,请教流程!
- 急~~~~~急~~~~~~急~~~~~~谢谢~~~~~~~谢谢!!!!
- 请教在DELPHI中,关于EXCEL操作的问题?
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;
不行么?
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;
结帐!