当前位置: 代码迷 >> ASP.NET >> ☆★☆ DbDataAdapter.Fill 方法的有关问题 ! 加急 ☆★☆
  详细解决方案

☆★☆ DbDataAdapter.Fill 方法的有关问题 ! 加急 ☆★☆

热度:10610   发布时间:2013-02-25 00:00:00.0
☆★☆ DbDataAdapter.Fill 方法的问题 ! 加急!!! ☆★☆
实在百思不得其解阿   !   望赐教   !


错误如下   :
------------------------------------------------------------------------
异常详细信息:   System.Data.SqlClient.SqlException:   子查询返回的值多于一个。当子查询跟随在   =、!=、 <、 <=、> 、> =   之后,或子查询用作表达式时,这种情况是不允许的。

源错误:  

行   641:   SqlDataAdapter   myDA   =   new   SqlDataAdapter(strQuery,   myConnection);
行   642:   DataSet   myDS   =   new   DataSet();
行   643:   myDA.Fill(myDS,   "menu ");
行   644:
行   645:   myConnection.Close();

源文件:   d:\LJ\eInfo\App_Code\data\DB.cs         行:   643  
-------------------------------------------------------------------------


代码如下:

#region   菜单
public   DataTable   getFirstMenu(string   admin)
{
SqlConnection   myConnection   =   new   SqlConnection(ConfigurationSettings.   AppSettings[ "ConnectionString "]);

string   strQuery;
if(admin== "0 ")
{
strQuery= "select   menuid,name,menulink   from   menu   where   fatherid=(select   menuid   from   menu   where   fatherid=-1)   order   by   seq ";      
}
else
{
strQuery= "select   menuid,name,menulink   from   menu   where   fatherid=(select   menuid   from   menu   where   fatherid=-1)   and   name!= '系统管理 '   order   by   seq ";      
}
                       
try
{
myConnection.Open();

SqlDataAdapter   myDA   =   new   SqlDataAdapter(strQuery,   myConnection);
DataSet   myDS   =   new   DataSet();
myDA.Fill(myDS,   "menu ");

myConnection.Close();

return   myDS.Tables[ "menu "];
}
catch   (Exception   err)
{
throw   new   Exception( "获取菜单的过程中出现错误。 ",   err);
}

}


------解决方案--------------------------------------------------------
这是SQL查询语句的问题

------解决方案--------------------------------------------------------
strQuery= "select menuid,name,menulink from menu where fatherid=(select menuid from menu where fatherid=-1) order by seq ";

strQuery= "select menuid,name,menulink from menu where fatherid=(select menuid from menu where fatherid=-1) and name!= '系统管理 ' order by seq ";
========================================================================

strQuery= "select menuid,name,menulink from menu where fatherid in (select menuid from menu where fatherid=-1) order by seq ";

strQuery= "select menuid,name,menulink from menu where fatherid in (select menuid from menu where fatherid=-1) and name!= '系统管理 ' order by seq ";


你的select menuid from menu where fatherid=-1返回的记录是多个,不能用 =

------解决方案--------------------------------------------------------
select top 1 menuid from menu where fatherid=-1
  相关解决方案