程序部分:
string Oid = CleanStringInputText(Request.Form[ "idList "].ToString().Trim());
SqlCommand cmdd = new SqlCommand( "Del ",conn);
cmdd.CommandType = CommandType.StoredProcedure;
cmdd.Parameters.Add(new SqlParameter( "@Userid ",Userid));
cmdd.Parameters.Add(new SqlParameter( "@Oid ",Oid));
cmdd.Parameters.Add(new SqlParameter( "@Fen ",Fen));
cmdd.ExecuteNonQuery();
conn.Close();
存储过程:
CREATE PROCEDURE Del
(
@Userid int,
@Oid varchar(20)
)
AS
DECLARE @errorFound tinyint
Select @errorFound = 0
BEGIN TRANSACTION
delete OfferList where Userid=@Userid and Oid in (@Oid)
IF @@ERROR > 0 SET @errorFound = 1
IF (@@ERROR > 0) OR (@errorFound > 0)
ROLLBACK
ELSE
COMMIT
GO
运行错误提示:
将 varchar 值 '141,142,147,149 ' 转换为数据类型为 int 的列时发生语法错误
所有分都加上了,请大哥大姐们帮帮忙吧......
------解决方案--------------------------------------------------------
实在不行 建议用SQL语句删除。。
------解决方案--------------------------------------------------------
Oid 里面因该是多个 序号. 不是LZ这么做的 你应该先用STRING拆分好 ID 生成一个数组 然后执行多次删除. 一个循环处理 直到数组里的ID 都执行过
------解决方案--------------------------------------------------------
上面写错了,少了一个 execute
CREATE PROCEDURE Del
(
@Userid int,
@Oid varchar(200)
)
AS
DECLARE @ERRORFOUND tinyint
DECLARE @sqlstring nVARCHAR(200)
SET @ERRORFOUND = 0
BEGIN TRANSACTION
SET @sqlstring = N 'delete OfferList where Userid=@Userid and Oid in ( ' + @OID + ') '
execute sp_executesql @sqlstring
SET @errorFound = @@ERROR
IF (@errorFound > 0)
SET @errorFound = 1
ROLLBACK
ELSE
COMMIT
GO