关于VF+SQL程序中的SQLEXEC()函数使用的问题。

myperry 2003-01-22 02:17:26
关于VF+SQL程序中的SQLEXEC()函数使用的问题。

我做这段程序的思路是这样的:先在SQL上建一个存储过程,用于判断删除条件是否成立,
然后在vf中调用此存储过程,如果不能删除资料时,则根据返回值m1作出对应的中文提示。

一:在SQL7中所建的存储过程如下:
CREATE PROCEDURE [del_tr_shch1] @shenchid31 char(8), @YourError int output
AS
declare @shul31 int
set @YourError = 0
set @shul31=-1

select @shul31 = shu_bt from tr_shch_dd where tr_shch_dd.shenchid = @shenchid31
if (@shul31>=0) set @YourError = 1
else
begin
if (@YourError = 0) select @shul31 = shul from tr_yll where tr_yll.shenchid = @shenchid31
if (@shul31>=0) set @YourError = 2
else
begin
if (@YourError = 0) select @shul31 = shul from tr_shch3 where tr_shch3.shenchid = @shenchid31
if (@shul31>=0) set @YourError = 3
else
begin
if (@YourError = 0) select @shul31 = shul from tr_chpr where tr_chpr.shenchid = @shenchid31
if (@shul31>=0) set @YourError = 4
end
end
end
if (@YourError = 0)
begin
delete from tr_shch1 where (tr_shch1.shenchid = @shenchid31 and tr_shch1.shu_tl = 0)
delete from tr_shch2 where (tr_shch2.shenchid = @shenchid31)
end

二:在SQL Query中用如下语句测试时,一切正常。
declare @shenchid31 int,@m1 int
set @shenchid31 = '10000001'
exec del_tr_shch1 @shenchid31, @m1 output

三:在VF中用如下语句调用,每当运行到SQLEXEC()处时,总会提示错误(Operator/operand type mismatch)
LOCAL shenchid31,m1
m1=0
SELE tr_shch1
shenchid31=allt(tr_shch1.shenchid)
IF messagebox("你确定要删除目前的这一笔生产指令吗?",4+32+256)=6
sele tr_shch1
=SQLEXEC(myconnect,'exec del_tr_shch1 '+ shenchid31 +','+m1 output)
DO case
CASE m1=1
MESSAGEBOX('此生产指令'+shenchid31+' 还有订单投料明细存在,不可删除!')
CASE m1=2
MESSAGEBOX('此生产指令'+shenchid31+' 已经有发料,不可删除!')
CASE m1=3
MESSAGEBOX('此生产指令'+shenchid31+' 已经有输入在线完成/(报废)数量,不可删除!')
CASE m1=4
MESSAGEBOX('此生产指令'+shenchid31+' 已经有输入库数量,不可删除!')
ENDCASE
ENDIF

请问:
1. SQLEXEC(myconnect,'exec del_tr_shch1 '+ shenchid31 +','+m1 output)这一语句错在哪里?应该怎样写?
2. 假如换一种方式,在del_tr_shch1存储过程尾部,使用return m1返回值,请问用SQLEXEC()语句又应如何写?

...全文
542 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
SE1 2003-01-23
  • 打赏
  • 举报
回复
如果不是笔误,那么语句
=SQLEXEC(myconnect,'exec del_tr_shch1 '+ shenchid31 +','+m1 output)
中存在语法错误:sqlexec的第二个参数应该是一个字符串,但你写的是一个字符串('exec del_tr_shch1 '+ shenchid31 +',')与一个整数(m1)相加!
应该是:
=SQLEXEC(myconnect,'exec del_tr_shch1 '+ shenchid31 +','+str(m1)+' output')
jin888888 2003-01-23
  • 打赏
  • 举报
回复
你的SQL Sever是不是要區分大小寫呀。
流星尔 2003-01-23
  • 打赏
  • 举报
回复
1、少了空格。语法就不正确了。
SQLEXEC(myconnect,'exec del_tr_shch1 ? shenchid31','cursorname')这一语句错在哪里?应该怎样写
2、存储过程改成
CREATE PROCEDURE [del_tr_shch1] @shenchid31 char(8)
AS
declare @shul31 int
set @YourError = 0
set @shul31=-1

if ……
set @yourerror=1
if ……
set @yourerror=2
……

select @yourerror

然后在客户端用第一个问题的答案调用时,在cursorname里已经包含了返回值。当然,要把select @yourerror放在存储过程的最后面
iceli 2003-01-23
  • 打赏
  • 举报
回复
顶。
我也急于知道如何在foxpro中接收SQL的返回值。
iceli 2003-01-23
  • 打赏
  • 举报
回复
弓虽贝斤,果然可以,我试了半天就差一个问好,厉害!
谢谢SE1 !!!!!
SE1 2003-01-23
  • 打赏
  • 举报
回复
无所谓,关键在于:“sqlexec的第二个参数应该是一个字符串”
但是,直接这样不能返回输出参数。应该这样:
=SQLEXEC(myconnect,'exec del_tr_shch1 '+ shenchid31 +', ?@m1')
返回值就存储在变量m1中。

iceli 2003-01-23
  • 打赏
  • 举报
回复
MS SQL里没有逻辑型,用我说的方法可以取出除text和image外的其他类型(只要能写到临时表里就行)。 ^_^
iceli 2003-01-23
  • 打赏
  • 举报
回复
好像这样也不能取回变量到vfp中,我现在使用变通的方法,在存储过程中建立一个临时表,然后将变量写入表中,再在存储过程中select出来,vfp执行存储过程后会在本地产生cursor,在从cursor中取出就行了,这样有一个额外的好处,那就是可以直接获得numeric值而不是只能得到int值了。

其实这样做增加不了多少代码。

希望对你有帮助。
myperry 2003-01-23
  • 打赏
  • 举报
回复
謝謝各位:
我馬上試下!

TO: SE1()
首先真心謝謝你的指點! 應該是你說的對.
但是同時我又想進一步問一下:"如果返回值M1是 小數,邏輯.t. 又該怎麼辦? "
myperry 2003-01-22
  • 打赏
  • 举报
回复
救命啦!!!
jin888888 2003-01-22
  • 打赏
  • 举报
回复
關注

2,749

社区成员

发帖
与我相关
我的任务
社区描述
VFP,是Microsoft公司推出的数据库开发软件,用它来开发数据库,既简单又方便。
社区管理员
  • VFP社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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