您好,怎样用查询控件使用存储过程,Delphi6 + Sql Server 2000 ,谢谢(40分)

P

pcgod

Unregistered / Unconfirmed
GUEST, unregistred user!
存储过程如下:
create proc getmoney
@name char(20),@theMoney int output
as
begin
select @theMoney = money from one where name = @name
end
GO
-------------------------------------------
前边:
object ADOQuery2: TADOQuery
Connection = ADOConnection1 //只指定了链接没有指定参数
Parameters = <>
Left = 96
Top = 96
end
//以下不能取到 Money ,编译无错执行错误
with ADOQuery2 do
begin
Close ;
Sql.Clear ;
Sql.Text := 'exec getmoney ''aaa'',0' ;
Open ;
Label1.Caption := IntToStr(Parameters.ParamByName('themoney').Value) ;
end;

请您指导,谢谢
 
在查询控件里用SQL中的语句执行。
 
要不直接用TADOStoredProc
 
YFeral :
您好,我不会用那个呀

 
用Tadodataset 使用方法 和 query一样,可以 调用存储过程
 
如果不直接用 TADOStoredProc ,而使用 查询控件 可不可以使用存储过程 ?
如果可以,那么存储过程的参数怎样引入和传出 ?
谢谢大家
 
sql.text := 'exec sp_get_dfd ''' + 参数一 + ''', ''' + 参数二 + ''''
这样不用行了
 
但我得不到返回值

sql.text := 'exec sp_get_dfd ''' + 参数一 + ''', ''' + 参数二 + ''''

我的:
Sql.Text := 'exec getmoney ''aaa'',0' ;
有参数的,但我用 Query 得不到返回值


大家再指导再指导 :)

 

with ADOQuery2 do
begin
Close ;
Sql.Clear ;
Sql.add := 'exec getmoney :p1,:p2' ;
Parameters.parambyname('p1').value:='aaa';
Parameters.parambyname('p2').value:=0;
excesql ;
Label1.Caption := IntToStr(fields[0].value) ;
end;
 
楼上您好:
你的代码调试后不能得到结果,这样修改后得到的仍然是 0

with ADOQuery2 do
begin
Close ;
Sql.Clear ;
Sql.add('exec getmoney :p1,:p2') ;
Parameters.parambyname('p1').value:='aaa';
Parameters.parambyname('p2').value:=0;
ExecSql ;
Label1.Caption := IntToStr(Parameters.ParamByName('p2').value) ;
// Label1.Caption = '0' ,也就是说,还是没有取得返回值
end;
 
sql.text := 'exec getmoney ''aaa'', 0';
这样写是对的,你的过程是否写对呢?
 
select @theMoney = money from one where name = @name

你过程这样写不对
这样是给@thmoney变量赋值,所以没返回结果
 
create proc getmoney
@name char(20),@theMoney int output
as
begin
select @theMoney = money from one where name = @name
select @theMoney //!!!!!!!
end
QRY或adoqry用open打开,别用execsql
 
那怎样才能有返回结果呢 ?

望大家继续指导


加一句 :
create proc getmoney
@name char(20),@theMoney int output
as
begin
select @theMoney = money from one where name = @name
Select @theMoney as Result
end

with ADOQuery2 do
begin
Sql.Text := 'exec getmoney ''bbb'',0.0';
Open ;
Label1.Caption := FloatToStr(FieldByName('result').Value) ;
end;
可以 ,不过为什么只有加这一句才可以得到返回? 在 StoredProc 控件中用时不用
改写存储过程的呀,是不是 Query 对存储过程的访问有局限性 ?望大家指导
 
不用as result,直接qry.fields[0].as...即可,我一直都用qry直接调用存储过程,不用
存储过程控件,记得当时从3.0到5.0转化时,当时的存储过程控件有问题。
select @sss=....语句是给@sss变量赋值,并不是对外返回,当然不行了,要返回的话,
加上是应该的,原来不加也行,倒是不应该的
 
同意 一生中最爱
 
谢谢大家
 
顶部