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

x
?
Solved

Where Query Syntax Help in  C# Code Behind

Posted on 2011-09-30
4
Medium Priority
?
236 Views
Last Modified: 2013-12-16
Hope this is an easy one.  I have a combobox in silverlight that is querying from a database service with a where clause.  The data has commas so it works when using the single quotes, but I can't figure out the query code in C# to get the single quotes to work.  

This works outside of Visual Studio
(MBR_112th = 'LastName, FirstName MiddleInitial.')


queryName.OutFields.AddRange(new string[] { "MBR_112TH", "DIST", "WEBSITE", "PERSONAL_WEBSITE" });
queryName.Where = "MBR_112TH = " + QueryComboBoxName.SelectedIndex.ToString();

Open in new window

0
Comment
Question by:Gregory3
[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
4 Comments
 
LVL 10

Accepted Solution

by:
dwe761 earned 1000 total points
ID: 36892835
did you try this?
queryName.OutFields.AddRange(new string[] { "MBR_112TH", "DIST", "WEBSITE", "PERSONAL_WEBSITE" });
queryName.Where = "MBR_112TH = '" + QueryComboBoxName.SelectedIndex.ToString() + "'";

Open in new window

0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 1000 total points
ID: 36894152
You might find it a tad more readable to use string.Format, though dwe761's approach should work as well:

queryName.OutFields.AddRange(new string[] { "MBR_112TH", "DIST", "WEBSITE", "PERSONAL_WEBSITE" });
queryName.Where = string.Format"MBR_112TH = '{0}'",  QueryComboBoxName.SelectedIndex.ToString());

Open in new window


where "{0}" gets substituted for the first parameter after the format string (i.e. the first parameter to string.Format).
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36894156
P.S.

I forgot an opening parentheses on the function call. Corrected below:
queryName.OutFields.AddRange(new string[] { "MBR_112TH", "DIST", "WEBSITE", "PERSONAL_WEBSITE" });
queryName.Where = string.Format("MBR_112TH = '{0}'",  QueryComboBoxName.SelectedIndex.ToString());

Open in new window

0
 

Author Closing Comment

by:Gregory3
ID: 36905533
Thanks guys.  Both worked in different situations.
0

Featured Post

Industry Leaders: 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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

618 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