none
DataTable.Select(COLUMN like '???010???') - How do I search with position constraints? RRS feed

  • Question

  •  

    I have a DataTable with a single of numbers named ACC9.

    Here is an example of the table's contents:

    Code Block

    ACC9

    000000000

    024010001
    024010003
    024010101
    024010102
    024010111
    024010115
    024101000

     

    I have provided Search functionaly for both these columns through a TextBox where the user types in the Search Param, allowing the '%' character for LIKE searches using the DataTable.Select procedure.

     

    Example:

    UserInput: "%010%"

    Results:

    Code Block

    DataTable.Select("ACC9 like '%010%'");

     

    ACC9

    024010001
    024010003
    024010101
    024010102
    024010111
    024010115
    024101000

     

    In SQL its possible to search for the EXACT string using ACC9 like '___010___'.

    How do I do this using DataTable.Select?

    Example

    UserInput: "???010???" or "***010***" (open to suggestion)

    Expected Results:

    Code Block

    ACC9

    024010001
    024010003
    024010101
    024010102
    024010111
    024010115

    (Notice, only returns records where POSITION corresponds to user input)

    Wednesday, December 5, 2007 5:43 AM

Answers

  • Expressions for Select method of the DataTable support only one wildcard, which is * or %. There is no support for other wildcards, similar to SQL statements. Basically you have two choices: 1. Use SQL statements directly against database or 2. Implement some sort of custom code that would loop through the records in a DataTable and check value using Regular Expressions or some other type of logic.

     

    Friday, December 7, 2007 11:05 AM
    Moderator