Muhammad Murad Haider
Muhammad Murad Haider

Reputation: 1487

Subquery returned more than 1 value.. query C# exception

i made a simple query joining two tables in the database using inner join. the query is given as follows:

Select t1.UserName,t1.Title,t1.FirstName,t1.LastName,t1.MiddleName,t1.IsActive,t1.ProgramID,t2.Email
from table1 t1
inner join table2 t2 on t1.UserId = t2.UserId

the query executes well in SQL Server Management Studio and returns rows as needed but while debugging my code in Visual Studio, when it reaches at

adapter.fill(dataset);

it throws the following exception:

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

here is the C# code snippet:

string selectCmd = @"Select t1.UserName,t1.Title,t1.FirstName,t1.LastName,t1.MiddleName,t1.IsActive,t1.ProgramID,t2.Email
from table1 t1
inner join table2 t2 on t1.UserId = t2.UserId ";
DataSet dataset = new DataSet();
                   using (SqlConnection conn = new SqlConnection(MyConnString))
                   {
                       SqlDataAdapter adapter = new SqlDataAdapter();
                       adapter.SelectCommand = new SqlCommand(selectCmd, conn);
                       conn.Open();
                       adapter.Fill(dataset);
                   }

Any suggestions please?? Any help would be greatly appreciated.

Upvotes: 2

Views: 1580

Answers (2)

Muhammad Murad Haider
Muhammad Murad Haider

Reputation: 1487

ok guys it was a timer job issue. one has to restart the sharepoint timer service before deploying the solution.

Upvotes: 0

Patan
Patan

Reputation: 1

Your join returning more than one value and you're trying to put these values in a single parameter..

Example: ----It's your error query

     DECLARE @Test INT 
SET @Test = (SELECT ID FROM ABC A INNER JOIN XYZ X ON A.ID = X.AID)

Solution:

     DECLARE @Test INT 
   SET @Test = (SELECT TOP 1 ID FROM ABC A INNER JOIN XYZ X ON A.ID = X.AID)

Upvotes: 0

Related Questions