[RESOLVED] DataTable.Select question-VBForums
Results 1 to 5 of 5

Thread: [RESOLVED] DataTable.Select question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    786

    Resolved [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,

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,772

    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.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    786

    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.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,772

    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.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    786

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.