Solved

Missing Operand after 's' Operator

Posted on 2009-05-04
2
1,900 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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

695 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