DataView sort fails to sort on fields with comma in field names

M

Mone Hsieh

hi all

I have a dataset which has column with comma in its name.

How do I use DataView to sort it properly? The DataView.Sort always break
the line when it sees a comma. Then it complains about field name being
invalid. I've tried quoting my field name with '"' or ''' but they all fail
the same way.

any idea how to make it work?

Mone
 
E

Erik Frey

Mone Hsieh said:
hi all

I have a dataset which has column with comma in its name.

How do I use DataView to sort it properly? The DataView.Sort always break
the line when it sees a comma. Then it complains about field name being
invalid. I've tried quoting my field name with '"' or ''' but they all fail
the same way.

any idea how to make it work?

Mone

Short of suggesting to not have column names with commas, I would do
something like this:

As far as I know, the Sort property will not support column names with
commas. It won't let you escape the comma. So instead, you can add an
expression column to the source table. If you are trying to sort on a
column named "Foo,Bar", then you could do this:

myTable.Columns.Add( "FooBarCopy",
custTable.Columns["Foo,Bar"].DataType, "[Foo,Bar]" );

This creates a column that uses the Expression property to reference to
the data in the original column. Now you can sort on the new column:

myView.Sort = "FooBarCopy";

Erik
 

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

Top