DataTable Select - Undefined function error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ArunDhaJ

    DataTable Select - Undefined function error

    Hi,
    I've to filter rows from DataTable Select

    There is a column named "Phone" which contains values in the following
    format:
    (901) 789 1234<BR>(901) 789 1235<BR>(901) 789 1221

    I need to filter based on the phone number. the search criteria could
    be 9017891221 or 891221.
    this string should filter the above column

    I've tried in SQL be replacing the '(', ')' and spaces as
    9017891234<BR>9 017891235<BR>90 17891221
    and performed search. It worked fine..

    When i tried in Select method gives Unknown Function
    REPLACE() error

    I've used
    REPLACE(REPLACE (REPLACE(Phones , ' ', ''), '(' , ''), ')', '') like
    '%891221%'


    Is there any way to achieve the same to filter the data?


    Thanks in Advance
    - ArunDhaJ
  • Pavel Minaev

    #2
    Re: DataTable Select - Undefined function error

    On Jul 4, 6:50 pm, ArunDhaJ <arund...@gmail .comwrote:
    Hi,
    I've to filter rows from DataTable Select
    >
    There is a column named "Phone" which contains values in the following
    format:
    (901) 789 1234<BR>(901) 789 1235<BR>(901) 789 1221
    >
    I need to filter based on the phone number. the search criteria could
    be 9017891221 or  891221.
    this string should filter the above column
    >
    I've tried in SQL be replacing the '(', ')' and spaces as
    9017891234<BR>9 017891235<BR>90 17891221
    and performed search. It worked fine..
    >
    When i tried in Select method gives Unknown Function
    REPLACE() error
    >
    I've used
    REPLACE(REPLACE (REPLACE(Phones , ' ', ''), '(' , ''), ')', '') like
    '%891221%'
    >
    Is there any way to achieve the same to filter the data?
    Unfortunately, the syntax of the filter expression for
    DataTable.Selec t() does not provide for any equivalent to REPLACE.
    However, in .NET 3.5, you may use LINQ to DataSet to query, and
    regexes to clean up the string:

    DataTable dt = ...;
    Regex insignificantCh aracters = new Regex("[() ]");
    IEnumerable<Dat aRowresult =
    from row in dt.AsEnumerable ()
    let phones = row.Field<strin g>("Phone").Spl it(new[] {"<BR>"},
    StringSplitOpti ons.None).Selec t(phone =>
    insignificantCh aracters.Replac e(phone, ""))
    where phones.Contains ("891221")
    select row;

    In .NET 2.0, you'll have to resort to writing the same thing manually
    using foreach.

    Comment

    • ArunDhaJ

      #3
      Re: DataTable Select - Undefined function error

      Hi,
      would this operation in foreach loop would hit the performance?

      manually looping in DataTable rows and removing those rows that doesnt
      match may hit performance right?

      -ArunDhaJ

      Comment

      • Pavel Minaev

        #4
        Re: DataTable Select - Undefined function error

        On Jul 5, 8:53 am, ArunDhaJ <arund...@gmail .comwrote:
        Hi,
        would this operation in foreach loop would hit the performance?
        >
        manually looping in DataTable rows and removing those rows that doesnt
        match may hit performance right?
        >
        -ArunDhaJ
        Not very likely. DataTable is not a proper indexed data store, so
        Select() will, most likely, just use foreach internally. If you need
        to filter large data sets, you should use a proper relational
        database, and do the filtering in SQL requests to that.

        Comment

        • ArunDhaJ

          #5
          Re: DataTable Select - Undefined function error

          Thanks Pavel, I've implemented using foreach and it works fine now.

          Sorry for delayed response... ;)

          -ArunDhaJ

          Comment

          Working...