delphi:将paradox改用MSSQL后,查询语句出了问题!(很菜的问题,50分相送)
Delphi5+MSSQL2000
数据库连接是BDE的ODBC通道
TEdit,TButton,TDBGrid,TQuery进行多表查询
按钮单击事件写法如下:
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add('select 读者号,读者姓名,书号,书名,借书日期,状态');
Query2.SQL.Add('from book,borrow,reader');
Query2.SQL.Add('WHERE 读者号 = : sbookstore1 AND ');
Query2.SQL.Add('borrow.书号 = book.书号 AND ');
Query2.SQL.Add('borrow.读者号 = reader.读者号');
Query2.SQL.Add('ORDER BY 状态 DESC, 借书日期 DESC');
Query2.ParamByName('sbookstore1').Asstring:= edit2.text;
Query2.PREPARE;
Query2.ExecSQL;
Query2.Active:=True;
运行结果报错:Query2:Parameter 'sbookstore1' not found
另:1.原先采用Paradox做数据库,程序运行正确。
2.单表查询也是正确的,如下:
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('select * from book');
Query1.SQL.Add('where 书号=:sbookstore');
query1.ParamByName('sbookstore').Asstring:= edit1.text;
Query1.PREPARE;
Query1.ExecSQL;
Query1.Active:=True;
edit1.text:='';