-
Dec 31st, 2012, 04:18 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] DataTable.Select question
For the FilterExpression on the DataTable.Select method can I have more than one filter. Like this:
Code:
String expression = "[ProductID] = '" + PMTDProductID + "' && [CustNo] = '" + APMFCustNo + "'";
DataRow[] results = dtCust.Select(expression);
Currently this is throwing this error "Syntax error: Missing operand before '&' operator.". What am I doing incorrectly?
Thanks,
-
Dec 31st, 2012, 07:11 PM
#2
Re: DataTable.Select question
First things first, I strongly recommend using String.Format to build strings like that because it makes things much clear.
As for the questions, what you're doing wrong is not bothering to read the documentation when you have a problem. Why bother using the Help menu when you need help, right? If you had done that then you would have seen this:
Operators
Concatenation is allowed using Boolean AND, OR, and NOT operators. You can use parentheses to group clauses and force precedence. The AND operator has precedence over other operators. For example:
(LastName = 'Smith' OR LastName = 'Jones') AND FirstName = 'John'
When you create comparison expressions, the following operators are allowed:
<
>
<=
>=
<>
=
IN
LIKE
The following arithmetic operators are also supported in expressions:
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
% (modulus)
You could have answered your own question in a few minutes and learned more besides.
-
Jan 1st, 2013, 04:04 AM
#3
Thread Starter
Fanatic Member
Re: DataTable.Select question
While I duly appreciate your reponse, as a beginner in C# what in the error message could I have keyed on to find the answer? I took the error message and googled it and got back garbage. I realize that MSDN has a ton of excellent information, it is just not easily searchable by somebody starting out and not 'knowing' what to search for based on an ambigous error message. I will heed your informative advice and will attempt to assemble an answer. Thank you.
-
Jan 1st, 2013, 09:56 AM
#4
Re: DataTable.Select question
Searching the web for information on a specific error message is certainly one tool you can use to help solve an issue but that's not what I'm talking about. I'm talking about reading the MSDN documentation specifically and for the type and/or member you're using specifically. You are trying to call the DataTable.Select method and it's not working, so read the documentation for the DataTable.Select method. Click the method name in code and press F1. Tada! 2 seconds work and you have the documentation for the DataTable.Select method in front of you. Now you just read and follow links as needed. 3 or 4 minutes of that and you'd have found that very information that I quoted above and you'd have been able to answer your question for yourself with no help from anyone.
If you want to write software that other people are going to use then you really should be proficient at using software yourself and any Windows user should be familiar with the F1 key and the Help menu. They have been a staple of the Windows OS for many, many years so they require no programming knowledge or experience.
-
Jan 3rd, 2013, 08:02 PM
#5
Thread Starter
Fanatic Member
Re: DataTable.Select question
Sometimes the obvious can elude me.........
And yes, I am familiar with F1.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|