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

Time:07-16

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?

CodePudding user response:

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

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