How can I use LINQ in C# with a column containing a '-' character?

Viewed 50

I have a DataTable in C# and I am attempting to use LINQ to select rows. The issue I am encountering is that a hyphenated column name is being interpreted incorrectly.

Here is the code:

DataRow[] matches = myTable.Select("SUB-CATEGORY = '" + sc + "' AND BW = '" + bw + "'");

I am getting the error "Cannot find the column [SUB]".

How can I resolve this?

1 Answers

Thanks to the comments provided, the solution is as follows:

DataRow[] matches = myTable.Select("[SUB-CATEGORY] = '" + sc + "' AND BW = '" + bw + "'");
Related