var
Form5: TForm5;
state: integer;implementation{$R *.dfm}procedure TForm5.RadioGroup1Click(Sender: TObject);
begin
edit1.Clear;
case RadioGroup1.ItemIndex of
0: begin
state:=0;
end;
1: begin
state:=1;
end;
end;
end;procedure TForm5.Button1Click(Sender: TObject);
begin
query1.SQL.Clear; if state=0 then
begin
query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
query1.SQL.Add('from student,course,sc');
query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno');
query1.Prepare;
query1.params[0].asstring:=edit1.text+'%';
query1.UnPrepare;
end; if state=1 then
begin
query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
query1.SQL.Add('from student,course,sc');
query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno');
query1.Prepare;
query1.params[0].asstring:=edit1.text+'%';
query1.UnPrepare;
end; query1.Open;
end;end.
我在三个表student(....) course(...) 还有sc(....)表 意思想查综合信息.里面有student,course, sc表里的东西
但我上面上样写却行不通.大家能不能帮我看下错在哪里???
Form5: TForm5;
state: integer;implementation{$R *.dfm}procedure TForm5.RadioGroup1Click(Sender: TObject);
begin
edit1.Clear;
case RadioGroup1.ItemIndex of
0: begin
state:=0;
end;
1: begin
state:=1;
end;
end;
end;procedure TForm5.Button1Click(Sender: TObject);
begin
query1.SQL.Clear; if state=0 then
begin
query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
query1.SQL.Add('from student,course,sc');
query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno');
query1.Prepare;
query1.params[0].asstring:=edit1.text+'%';
query1.UnPrepare;
end; if state=1 then
begin
query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
query1.SQL.Add('from student,course,sc');
query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno');
query1.Prepare;
query1.params[0].asstring:=edit1.text+'%';
query1.UnPrepare;
end; query1.Open;
end;end.
我在三个表student(....) course(...) 还有sc(....)表 意思想查综合信息.里面有student,course, sc表里的东西
但我上面上样写却行不通.大家能不能帮我看下错在哪里???
begin
query1.SQL.Add
('select sc.sno,student.sname,student.sdept,course.cname,student.grade,student.ssex,student.sage');
query1.SQL.Add('from student,course,sc');
query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno');
query1.Prepare;
query1.params[0].asstring:=edit1.text+'%';//还有,我没发现你的参数在哪里
query1.UnPrepare;
end;
begin
query1.SQL.Clear; if state=0 then
begin
query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
query1.SQL.Add('from student,course,sc');
query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno');
query1.Prepare;
query1.params[0].asstring:=edit1.text+'%';
//query1.UnPrepare;
end; if state=1 then
begin
query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
query1.SQL.Add('from student,course,sc');
query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno');
query1.Prepare;
query1.params[0].asstring:=edit1.text+'%';
// query1.UnPrepare;
end; query1.Open;
end;
这样如何?
DELPHI 可以这样写:SELECT * FROM STUDENTD WHERE STU_ID=:ID
其中ID是参数
然后给参数赋值 QUERY1.PARAMETERS.PARAMETERSBYANME('ID').VALUE:='1';2,不要使用QUERY1.UNPREPARE,实在是没有必要
project project1.exe raised exceptin class elisterror with message "list index out of bounds(0)'.process stopped ,use step or run to continue
如:xymao123() 所写
begin
query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
query1.SQL.Add('from student,course,sc');
query1.SQL.Add('where course.cno=sc.cno and sc.sno=student.sno like :num');
query1.Prepare;
query1.params[0].asstring:=edit1.text+'%'; end; if state=1 then
begin
query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
query1.SQL.Add('from student,course,sc');
query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno like :no ');
query1.Prepare;
query1.params[0].asstring:=edit1.text+'%'; end; query1.Open;
end;
我后来这样写了参数但还是不行
不知道为什么???/
begin
query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
query1.SQL.Add('from student,course,sc');
query1.SQL.Add('where course.cno=sc.cno and sc.sno=student.sno like :num');
query1.Prepare;
query1.params[0].asstring:=edit1.text+'%'; end; if state=1 then
begin
query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
query1.SQL.Add('from student,course,sc');
query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno like :no ');
query1.Prepare;
query1.params[0].asstring:=edit1.text+'%'; end; query1.Open;
end;
我后来这样写了参数但还是不行
不知道为什么???/
---------------------------------------------------------------------------
like :num
前面应该有字段名吧 一般是 field1 like %a%