Solved

Missing Operand after 's' Operator

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

14 Experts available now in Live!

Get 1:1 Help Now