Column Header Problem in DataTable Select Method [Resolved]

Posted by T.saravanan under C# on 11/30/2010 | Points: 10 | Views : 3781 | Status : [Member] [MVP] | Replies : 1
Hi All,

I am using data filter from DataTable using Select method.In my case Column Header have a special character so in filter section comes error.

Here is my Code...

In this case its working fine..

string sCondition = string.Format("[{0}] = '{1}'", "Country Name", "India");
DataRow[ ] dr = dtData.Select(sCondition);


Problem is occured in this case...

string sCondition = string.Format("[{0}] = '{1}'", "Unit [in Cr]", "INR");
DataRow[ ] dr = dtData.Select(sCondition);


In this case Column Name have brace '[ ] ' so my filter condition is not working..
Exception thrown: "Cannot interpret token ']' at position 11 "
Please any one suggest me how to filter this type of column using Select method.

Advance Thanks.... :(

Thanks,
T.Saravanan



Responses

Posted by: T.saravanan on: 11/30/2010 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Hi All,

Thanks for your effort...

Now i am found out the solution..

Just add a slash ("\") in near to closing brace...


string sCondition = string.Format("[{0}] = '{1}'", "Unit [in Cr\]", "INR");
DataRow[ ] dr = dtData.Select(sCondition);


Reference :http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression%28VS.71%29.aspx

Cheers :)



Thanks,
T.Saravanan

T.saravanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response