SQL参数问题,高手指教

大王带我来巡山 2003-04-08 01:59:53
出现了另一个错误:"至少有一个参数没有值",可我看不出那里有问题,麻烦给我再看看,在线等答案:
with dm.adoq1 do
begin
close;
sql.Clear;
sql.add('select * from table0cpin where datepart(yy,indate)=:yr');
parameters.ParamByName('yr').value:=edit7.Text;
sql;
open;
first;
if eof and bof then showmessage('ok!总数是:'+inttostr(RecordCount));
end;
...全文
40 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
分我已经给大家了,可是问题在我这还是没能解决,还是上面的问题,希望你们再帮我!
  • 打赏
  • 举报
回复
to Bes96261(秋水孤鶩),hmilyice(旭日)
我现在重新用了一个adoquery,把参数取消了,可是出现"yyyy参数没有默认值",
难道datepart问题,我用的是delphi5.0,真是麻烦大家了

with dm.ADOQuery1 do
begin
close;
sql.Clear;
sql.add('select * from table0cpin where datepart(yyyy,indate)=2001');
//parameters.ParamByName('yi').value:=StrToInt(Edit7.Text);
sql;
open;
first;
if eof and bof then showmessage('ok!总数是:'+inttostr(RecordCount));
end;
hmilyice 2003-04-08
  • 打赏
  • 举报
回复
你有没有在dm.adoq1属性里设置了多个参数,我指的不是在代码中是在开发环境里
BES 2003-04-08
  • 打赏
  • 举报
回复
我試過了:
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add(' select * from Indent_M where DatePart(YYYY,IndentDate)=:YJ');
Parameters.ParamByName('YJ').value := StrToInt(Edit1.Text); //Edit1.Text := '2003' 四位
Open;
ShowMessage('記錄數為:'+IntToStr(RecordCount));
end;
end;
Means_pan 2003-04-08
  • 打赏
  • 举报
回复
你直接拼完整的SQL语句,可以实现的
  • 打赏
  • 举报
回复
to Bes96261(秋水孤鶩):
sql.add('select * from table0cpin where datepart(yy,indate)=:yr');
parameters.ParamByName('yr').AsInteger:=StrToInt(Edit7.Text);

我写改,还是不行,还是那个问题,再帮忙出出主意,谢谢了!
  • 打赏
  • 举报
回复
好谢谢大家这么热心,我先去试,如果没什么问题就来分分!
BES 2003-04-08
  • 打赏
  • 举报
回复
Showmessage('ok!总数是:'+inttostr(RecordCount));
BES 2003-04-08
  • 打赏
  • 举报
回复
sql.add('select * from table0cpin where datepart(yy,indate)=:yr');
parameters.ParamByName('yr').value:=edit7.Text;
這兩行有問題:
DataPart(YY,InDate) 返回的是一個數值型值與edit7.Text顯然是不會相等的

sql.add('select * from table0cpin where datepart(yy,indate)=:yr');
parameters.ParamByName('yr').AsInteger:=StrToInt(Edit7.Text);
jiaai 2003-04-08
  • 打赏
  • 举报
回复
用parameters.paramvalues['yi']:=edit7.text;
试试看
Taken 2003-04-08
  • 打赏
  • 举报
回复
if not (eof or bof) then showmessage('ok!总数是:'+inttostr(RecordCount));

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧