用户代码错误未处理sqlexception [英] sqlexception was unhandled by user code Error

查看:72
本文介绍了用户代码错误未处理sqlexception的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是错误:



子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。





我的sql查询是:



  USE  [aspnetdb] 
GO

/ * *****对象:StoredProcedure [dbo]。[sp_Permission]脚本日期:04/29/2013 09:38:00 ****** /
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

创建 过程 [dbo]。[sp_Permission]
@ Role名称 nvarchar 50 ),
@SubMenu nvarchar 50
as
开始
选择 Read_P,Write_P ,Update_P,Delete_P 来自 MenuMapping 其中 RoleName = @ RoleName SubMenuId =(选择 SubMenuId 来自 SubMenu 其中 SubMenuLcation = @ SubMenu)
end
GO


任何人都可以说可能的解决方案 这个...帮助我!!!

解决方案

请使用此代码。



使用条款而不是等于。







USE [aspnetdb]

GO



/ ******对象:StoredProcedure [dbo]。[ sp_Permission]脚本日期:04/29/2013 09:38:00 ****** /

SET ANSI_NULLS ON

GO



SET QUOTED_IDENTIFIER ON

GO



创建程序[dbo]。[sp_Permission]

@RoleName nvarchar(50),

@SubMenu nvarchar(50)

as

begin

从MenuMapping中选择Read_P,Write_P,Update_P,Delete_P,其中RoleName = @ RoleName和SubMenuId in(从SubMenu中选择SubMenuId,其中SubMenuLcation = @ SubMenu)

end

GO

 <   pre     lang   =  XML >  
从MenuMapping中选择Read_P,Write_P,Update_P,Delete_P,其中RoleName = @ RoleName和SubMenuId in(从SubMenu中选择SubMenuId,其中SubMenuLcation = @ SubMenu )
< / pre >


应该有'in'而不是'='接近'查询'中的子菜单'因为你的子查询包含多行,所以db会混淆哪一行必须采取,在插入之后将考虑所有行检查并给出您的子查询的所有匹配结果的结果


this is the error:

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.


My sql Query was:

USE [aspnetdb]
GO

/****** Object:  StoredProcedure [dbo].[sp_Permission]    Script Date: 04/29/2013 09:38:00 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

Create procedure [dbo].[sp_Permission]
@RoleName nvarchar(50),
@SubMenu nvarchar(50)
as
begin
select Read_P,Write_P, Update_P, Delete_P from MenuMapping where RoleName=@RoleName and SubMenuId=(select SubMenuId from SubMenu where SubMenuLcation=@SubMenu)
end
GO


can anyone say possible solution for this... help me!!!

解决方案

Please use this code.

use in clause instead of equal to.



USE [aspnetdb]
GO

/****** Object: StoredProcedure [dbo].[sp_Permission] Script Date: 04/29/2013 09:38:00 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

Create procedure [dbo].[sp_Permission]
@RoleName nvarchar(50),
@SubMenu nvarchar(50)
as
begin
select Read_P,Write_P, Update_P, Delete_P from MenuMapping where RoleName=@RoleName and SubMenuId in(select SubMenuId from SubMenu where SubMenuLcation=@SubMenu)
end
GO


<pre lang="xml">
select Read_P,Write_P, Update_P, Delete_P from MenuMapping where RoleName=@RoleName and SubMenuId in (select SubMenuId from SubMenu where SubMenuLcation=@SubMenu)
</pre>


there should be 'in' not '=' near to 'SubmenuID in (query)' reason your subquery is contain more than one row so db is confuse which row it has to take, after putting in it will consider all row to check and give you result for all matching result for your subquery


这篇关于用户代码错误未处理sqlexception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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