.NET · Development

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);

It worked like a charm.

Advertisements

10 thoughts on “DataTable.Select problem with column name having space

  1. Thanks, worked like a charm!
    I looked far and wide for this solution!

    in C#, you can just use something like:
    string sql = “SELECT [Network Name] FROM Info where [Network Name] LIKE ‘%Comp1%'”;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s