Query on DataView.Sort Property

D

Denzil

Hi,

I am using the DataView.Sort Property (on a DataView column) to sort
the View based on some condition.

Now the column that I need to sort contains characters and HTML code
that should not be considered when sorting is done. (e.g. -> <B>,
<FONT ...>, " , ' , etc...).
To illustarte:
Example 1
<B>This is a...</B> should be sorted as -> This is a... (disregard the
<B>)

Example 2
"Hello friends..." should be sorted as -> Hello friends... (disregard
the ")

The DataColumn.Expression Property does not support "PATINDEX". It
supports SUBSTRING & LEN though.

And I do not want to do this sorting in the SQL SP. Any pointers will
be appreciated.

Thanks for your time.

Cheerz,
Denzil
 
C

Chris Taylor

Hi,

Off the top of my head, maybe a solution would be to add a extra column to
the dataset (not the database) and put the clean text in the column. After
calling Fill() you can add the column and run through the records cleaning
the data ie. remove unwanted tags and punctuation etc. and putting the clean
text into the new column. Then you can use this 'cleaned' column as the sort
column.

Thinking about this solution I got another idea for populating the cleaned
column, I am sure it will *not* give great performance, but the code is
simpler. (And interesting, I was not sure it would work so I tested it).

Fill the DataSet using FillSchema( ds, SchemaType.Mapped ), then add the
column to the DataTable and add an event handler for the RowChanged event.
Then call Fill to populate the DataSet. As the DataTable in the DataSet is
populated the RowChanged events fires for each new row added by the Fill
procedure, if the event action is DataRowAction.Add clean the text of the
source column and set the value of the 'cleaned' column to the cleaned text.
Watch out, the event will fire twice because of the changing of the column
value so it is important to check the action.

Hope that helps

Chris Taylor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top