Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Missing Operand after 's' Operator

Posted on 2009-05-04
2
Medium Priority
?
1,959 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

610 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