使用游标从数据网格中删除多个记录 [英] Deleting multiple records from a datagrid using cursors

查看:89
本文介绍了使用游标从数据网格中删除多个记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们......

任何人都可以帮我解决这个问题....

我想删除数据网格中的多条记录cursors.the存储过程的参数是一个逗号分隔的字符串(User_ID),但我写的存储过程不起作用,任何人都可以帮助我,这对我来说是一个很大的帮助。当我执行程序和打印@@ FETCH_STATUS它打印的状态-1即没有记录....


CREATE PROCEDURE test_cur3(@User_ID varchar(100))

as


设置NOCOUNT


声明@UID字符(15)

DECLARE TESTCUR3 CURSOR

SELECT User_ID FROM Header WHERE User_ID in(@User_ID)


open TESTCUR3


FETCH NEXT FROM TESTCUR3

INTO @UID

WHILE @@ FETCH_STATUS = 0

BEGIN



update标题集已删除=' '1''WHERE User_ID = @UID


下一个来自TESTCUR3

INTO @UID

结束;


关闭TESTCUR3

DEALLOCATE TESTCUR3

GO

Hi Friends...
Can anyone plz help me out i''m stuck ....
I want to delete multiple records from a data grid using cursors.the parameter for the stored procedure is an comma seperated string(of User_ID),but the stored procedure which i had written is not working can anyone help me out,it would be a great help for me.when i execute the procedure and print @@FETCH_STATUS the status it prints -1 ie no record ....

CREATE PROCEDURE test_cur3(@User_ID varchar(100))
as

SET NOCOUNT ON

declare @UID char(15)
DECLARE TESTCUR3 CURSOR for
SELECT User_ID FROM Header WHERE User_ID in ( @User_ID)

open TESTCUR3

FETCH NEXT FROM TESTCUR3
INTO @UID
WHILE @@FETCH_STATUS = 0
BEGIN


update Header set Deleted=''1'' WHERE User_ID= @UID


FETCH NEXT FROM TESTCUR3
INTO @UID
END;

CLOSE TESTCUR3
DEALLOCATE TESTCUR3
GO

推荐答案

您尝试发送多少个用户ID ?我的第一个猜测是你的sp可能只使用一个ID。据我所知,您在1,2,3,4的行中以逗号分隔的字符串连接多个用户ID。这将成为您的输入参数,查询无法匹配:

SELECT User_ID FROM Header WHERE User_ID IN(''1,2,3,4'')


按下参数修改你的查询(如果你还没有这样做):


SELECT User_ID FROM Header WHERE User_ID IN(''1 '',''2'',''3'',''4'')
How many User IDs are you trying to send? My first guess is that your sp could possibly work with a single ID. I understand that you concatenate multiple User IDs in a comma delimited string along the lines of ''1,2,3,4''. That becomes your input parameter, which the query is unable to match:

SELECT User_ID FROM Header WHERE User_ID IN (''1,2,3,4'')

Massage the parameter to modify your query (if you haven''t done so yet):

SELECT User_ID FROM Header WHERE User_ID IN (''1'',''2'',''3'',''4'')


嗨......


你的回复,但我已经尝试按摩参数来修改查询

SELECT User_ID FROM Header WHERE User_ID IN(''1'','''',''3'', ''4'')


但是它仍然无法正常工作,你可以告诉我一些其他方法来解决这个问题。
Hi...

Thnks for your reply,but i had already tried to Massage the parameter to modify the query
SELECT User_ID FROM Header WHERE User_ID IN (''1'',''2'',''3'',''4'')

but still it''s not working, can u plz suggest me some other way to solve this problem.



嗨...


请回复你,但我已经尝试按摩参数来修改查询

SELECT User_ID FROM Header WHERE User_ID IN(''1'',' '2'','''',''4'')


但是它仍然没有用,你能不能告诉我一些其他方法来解决这个问题。
Hi...

Thnks for your reply,but i had already tried to Massage the parameter to modify the query
SELECT User_ID FROM Header WHERE User_ID IN (''1'',''2'',''3'',''4'')

but still it''s not working, can u plz suggest me some other way to solve this problem.



您是否尝试过传递一个值?


检查是否有效并发回POST。如果程序使用单个值,那么我们可以找出问题是通过多个值传递还是程序本身。

Have you tried by passing a single value?

Check if that is working and POST back. If the procedure is working with single value then we could trace out if the problem is with multiple value being passed or with the procedure itself.


这篇关于使用游标从数据网格中删除多个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆