Click here to Skip to main content
15,898,942 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am getting an exception thrown that doesn't make any sense to me - and would like some help, someone to explain why this is being thrown, and what I need to do to solve the problem ...

In my C# code ...

 SqlConnection thisConnection = new SqlConnection(@"Network Library=DBMS;Data Source=AZ75;database=MyDev;User id=usrread;Password=password;";);
try
{
    thisConnection.Open();
}
catch (Exception e)
{
    Console.WriteLine(e.ToString());
}

 string sDocIDsList = "202+211, 30+30";

 SqlDataAdapter da = new SqlDataAdapter();
 DataSet ds = new DataSet();

 SqlCommand tCommand = new SqlCommand();
 tCommand.CommandText = "GetReport";
 tCommand.Connection = thisConnection;
 tCommand.CommandType = CommandType.StoredProcedure;

 da.SelectCommand = tCommand;

 tCommand.Parameters.Add(new SqlParameter("@Return_Value", SqlDbType.Int));
 tCommand.Parameters["@Return_Value"].Direction = ParameterDirection.ReturnValue;

 tCommand.Parameters.Add(new SqlParameter("@DocIDsList", SqlDbType.VarChar));
 tCommand.Parameters["@DocIDsList"].Value = sDocIDsList;
 tCommand.Parameters["@DocIDsList"].Direction = ParameterDirection.Input;

 ds.Clear();

 try
 {
     da.Fill(ds);
 }
 catch (SqlException e)
 {
     Console.WriteLine(e.Message);
 }


When executing the da.Fill command - the system throws an exception, with the following text:


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


HELP !!! What does this mean???
Posted
Updated 15-Feb-12 6:04am
v2
Comments
manognya kota 15-Feb-12 12:10pm    
Can you post your code of stored procedure? As per the error message you are using a subquery which is returning multiple values where only one value is expected.

Hi,

I guess you are either assigning value into a variable in your select query in the stored procedure.
or comparing with a sub query.That query is returning more than one row.so cannot be compared as there are multiple values.
However it cannot be clarified until you post the code of your stored procedure.


Hope this helps.
 
Share this answer
 
v3
It means in your stored procedure you have a subquery that is returning more than one value. You need to look at your data.

For example, if you said

SQL
SELECT * FROM Table WHERE Column = (SELECT Column FROM Table2)


The subquery will return more than one record but you are using = so you get that error.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900