这几天在做课程设计,开发一个小型的学生成绩管理信息系统,我要实现查询并显示数据库表中的单条记录,比如输入某个学生的学号就显示该学号学生的信息,现在有个问题是我不管输入哪个学号,总是把整个表的信息显示出来了,代码如下:
procedure Tmainform.Button1Click(Sender: TObject);
begin
stuinformation2.ADOQuery1.Close;
stuinformation2.ADOQuery1.SQL.Clear;
stuinformation2.ADOQuery1.SQL.Add('select *from 学生成绩记录单 where 学生学号=:s学生学号');
stuinformation2.ADOQuery1.Parameters.ParamByName('s学生学号').Value:=strtoint(edit34.Text);
stuinformation2.ADOQuery1.Open;
stuinformation2.ADOTable1.Close;
stuinformation2.ADOTable1.Open;
stuinformation2.Show;
end;
请问该如何修改?
procedure Tmainform.Button1Click(Sender: TObject);
begin
stuinformation2.ADOQuery1.Close;
stuinformation2.ADOQuery1.SQL.Clear;
stuinformation2.ADOQuery1.SQL.Add('select *from 学生成绩记录单 where 学生学号=:s学生学号');
stuinformation2.ADOQuery1.Parameters.ParamByName('s学生学号').Value:=strtoint(edit34.Text);
stuinformation2.ADOQuery1.Open;
stuinformation2.ADOTable1.Close;
stuinformation2.ADOTable1.Open;
stuinformation2.Show;
end;
请问该如何修改?
去掉
stuinformation2.ADOTable1.Close;
stuinformation2.ADOTable1.Open;DataSource1的DataSet设置为adoquery1,dbgrid的datasource设置为datasource1
可以参考#6的回答