PC Review


Reply
Thread Tools Rate Thread

DataTable Select - Undefined function error

 
 
ArunDhaJ
Guest
Posts: n/a
 
      4th Jul 2008
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>9017891235<BR>9017891221
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
 
Reply With Quote
 
 
 
 
Pavel Minaev
Guest
Posts: n/a
 
      4th Jul 2008
On Jul 4, 6:50*pm, ArunDhaJ <arund...@gmail.com> wrote:
> 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>9017891235<BR>9017891221
> 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.Select() 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 insignificantCharacters = new Regex("[() ]");
IEnumerable<DataRow> result =
from row in dt.AsEnumerable()
let phones = row.Field<string>("Phone").Split(new[] {"<BR>"},
StringSplitOptions.None).Select(phone =>
insignificantCharacters.Replace(phone, ""))
where phones.Contains("891221")
select row;

In .NET 2.0, you'll have to resort to writing the same thing manually
using foreach.
 
Reply With Quote
 
ArunDhaJ
Guest
Posts: n/a
 
      5th Jul 2008
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
 
Reply With Quote
 
Pavel Minaev
Guest
Posts: n/a
 
      5th Jul 2008
On Jul 5, 8:53*am, ArunDhaJ <arund...@gmail.com> wrote:
> 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.
 
Reply With Quote
 
ArunDhaJ
Guest
Posts: n/a
 
      8th Jul 2008
Thanks Pavel, I've implemented using foreach and it works fine now.

Sorry for delayed response...

-ArunDhaJ
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Replace function in DataTable.Select ArunDhaJ Microsoft ASP .NET 2 4th Jul 2008 07:15 AM
DataTable.Select Aggreate function Stefan Schelling Microsoft Dot NET Framework 0 23rd Aug 2006 07:17 AM
Undefined Function Error on custom function =?Utf-8?B?QW1hbmRhIFBheXRvbg==?= Microsoft Access VBA Modules 3 19th Apr 2005 06:06 PM
Undefined Function Error =?Utf-8?B?S2Vu?= Microsoft Access Queries 6 18th Feb 2005 12:11 PM
Error: Undefined function Maureen Microsoft Access Queries 1 22nd Jun 2004 04:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:20 PM.