C # DataTable function doesn't work with special characters #

I have a datatable select like:

productData.Select("Name = 'AAA BBB # CCC'");

I know that the entry is there, it just does not work due to the # symbol. I tried to escape using [], for example:

productData.Select("Name = 'AAA BBB [#] CCC'");

but it still doesn't work. I know that for single quotes I double them, so it "becomes". But what other characters do I need to worry about and how to make this case work.

+3
source share
2 answers

Do you definitely need to use DataTables? That is why I was always very nervous from text query to DataTable.

, LINQ. DataTable , .

var query = products.AsEnumerable()
                    .Where(row => row.Field<string>("Name") == "AAA BBB # CCC");

, .. , , , .

+3

- ?

productData.Select(@"Name = 'AAA BBB # CCC'");
+2

Source: https://habr.com/ru/post/1766704/


All Articles