Monday, July 20, 2009

DataTable.Select problem with column name having space

DataTable.Select problem with column name having space

I have a DataTable with a column named “Insurance ID”. I don’t have any control over how I am getting this data. I want to select a particular row but the DataTable.Select method fails because there is a space in the column name.

I have tried:
1) string expr= “Insurance ID = ‘1′”
2)
string expr=“‘Insurance ID‘ = ‘1′”
3)
string expr=“\”Insurance ID\” = ‘1′”


used with the following:

DataRow [] oaDR = myDataTable.Select(expr);

1 and 3 fail with an exception. 2 runs but nothing is found.

After some research I solved the issue using

string expr=”[Insurance ID]=’1′”

DataRow [] dRow = myDataTable.Select(expr);

No comments:

Post a Comment