日期:2014-05-18  浏览次数:21136 次

子查询返回的值不止一个
System.Data.SqlClient.SqlException: 子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。

行 78: cmd.CommandType = ct;
行 79: cmd.Parameters.AddRange(paras);
行 80: res = cmd.ExecuteNonQuery();
行 81: }
行 82: return res;

存储过程:
。。。
ALTER PROCEDURE [dbo].[New_Delect] 
@id int
AS
BEGIN
-- 先删除评论意见
delete pingrun where newsid=@id
-- 再删除新闻
delete News where id=@id
END

应该怎么写才对?

------解决方案--------------------
不是这一段的,这一段没有子查询.
------解决方案--------------------
如果子查询返回的值不止一个,那你就不能用:

select * from tb where col1=(你的那个子查询)
而要用:
select * from tb where col1 in (你的那个子查询)

------解决方案--------------------
SQL code
select * from tb where col1=ANY(子查询)

------解决方案--------------------
探讨
还有个中间部分: 
public bool Delete(string dwID) 

//Todo:删除 
bool flag = false; 
String cmdText = "存储过程名"; 
SqlParameter[] paras = new SqlParameter[]{ 
new SqlParameter("@ID",ID) 
}; 
int res = sqlhelper.ExecuteNonQuery(cmdText, paras, CommandType.StoredProcedure); 
if (res…