Solved

Missing Operand after 's' Operator

Posted on 2009-05-04
2
1,803 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
2 Comments
 
LVL 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now