By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,923 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

sort column as int, not string after populate dataTable from a file

P: n/a
Hi,

I read a csv file to a datatable. I don't know what are the column types at
this moment, so I treat all columns as string type.

After I read data from file, I use dataTable.Select(condition) to select
some lines.

The problem is with numeric columns, since in datatable, it is string type,
it compares rows as string so make Select() return wrong set of rows.

I was trying to change DataColumn type, but it is an error since there are
already data in the column.

What is the best way to solve this problem? Any input is highly appreciated!

Ryan Liu
May 15 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Ryan,

You could use Convert function within your select - this way you will be
able to compare as a numeric datatype.
Not sure how can you know that a column contains numeric values when using
Select, but cannot use this knowledge when loading the data...

"Ryan Liu" wrote:
Hi,

I read a csv file to a datatable. I don't know what are the column types at
this moment, so I treat all columns as string type.

After I read data from file, I use dataTable.Select(condition) to select
some lines.

The problem is with numeric columns, since in datatable, it is string type,
it compares rows as string so make Select() return wrong set of rows.

I was trying to change DataColumn type, but it is an error since there are
already data in the column.

What is the best way to solve this problem? Any input is highly appreciated!

Ryan Liu
May 16 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.