Solved

Missing Operand after 's' Operator

Posted on 2009-05-04
2
1,861 Views
Last Modified: 2012-05-06
Experts,

While attempting to apply a Filter expression to a DataSource, I get the following error:

Missing Operand after 's' Operator

In the attached code snippet, you can see the SQL statement that I build and how I apply it.  The query returns a 65 integer value.

What am I missing?
sql="(SELECT s.Statement_ID "; 
				sql=sql + "FROM ((((STATEMENTS s ";
				sql=sql + "INNER JOIN Topics_To_Statements tts ON tts.Statement_ID=s.Statement_ID) ";
				sql=sql + "INNER JOIN Topics t ON t.Topic_ID=tts.Topic_ID) " ;
				sql=sql + "INNER JOIN Subjects_To_Topics stt ON stt.Topic_ID=t.Topic_ID)  ";
				sql = sql + "INNER JOIN Disciplines_To_Subjects dts ON dts.Subject_ID=stt.Subject_ID) ";
			   sql= sql + " WHERE dts.Discipline_ID=" + disciplineID.ToString() + ")";
				sql = sql + " ORDER BY t.Topic_Name ASC ";
 
			  //cce
				dsrcStatements.FilterExpression = "Statement_ID IN " + sql;
				gridStatements.DataBind();

Open in new window

0
Comment
Question by:NigelRocks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24299769
>                        dsrcStatements.FilterExpression = "Statement_ID IN " + sql;
from what I know, you cannot do that.

you will either have to rerun the statement to fill the data source, or you will need to run that subselect, and get the list of values as comma-separated string, and put that into the filter expression.
0
 
LVL 9

Expert Comment

by:tculler
ID: 24299888
You've got a bit too much going on here--first thing I suggest is cleaning up your code. Instead of saying:

sql = sql + " .... ";
It is common practice to say:
sql += " .... ";

However, in this case, you don't need to have these seperate statements like that--in fact, it actually slows the concatenation process down, creating more String objects than is necessary. I'm not sure how you're implementing everything, but I'll give you a half psuedocode half code method you may use (just replace the last time you used the variable "sql" with a method call to the following method):

public System.String GetCommaSeperatedList(System.String mySqlStatement)
{
     System.Text.StringBuilder bldr = new System.Text.StringBuilder();
     // Execute SQL Statement supplied in parameters
     foreach(DataRow record in /*Executed SQL Statement*/)
     {
          bldr.Append(record[/*Get desired field*/]);
          bldr.Append(", ");
     }
     bldr.Append(")"); // Complete "IN" parentheses
     return bldr.ToString();
}

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question