0

A Database has a data like these

OVS0001#R1

OVS0001#R2

OVS0001#R3

I try to filter by using Select() function .

       Datatable.Select(" ITEM_CODE='OVS0001#R1' ")

The error message shows like these

      The expression contains invalid date constant '#R1"'.
Fame th
  • 1,018
  • 3
  • 17
  • 37
  • Does this answer your question? [Correct way to escape characters in a DataTable Filter Expression](https://stackoverflow.com/questions/386122/correct-way-to-escape-characters-in-a-datatable-filter-expression) – MatSnow Aug 27 '20 at 07:13
  • I try to replaced by two character( # to be ##). But It is not work because it see '#' to be date. – Fame th Aug 27 '20 at 07:31
  • 1
    You can also use the DataView.Filter, e.g., `DataTable.DefaultView.RowFilter = "ITEM_CODE LIKE '%OVS0001#R1%'"`. That doesn't require escaping chars (well, it doesn't need *more* escapes). – Jimi Aug 27 '20 at 07:34
  • If I understand [this answer](https://stackoverflow.com/a/2928226/2967965) correctly, then it should be `"ITEM_CODE LIKE 'OVS0001[#]R1'"`. – MatSnow Aug 27 '20 at 07:38
  • @MatSnow The standard `'%...%'` is enough here. – Jimi Aug 27 '20 at 07:39
  • I couldn't reproduce your problem (with .net 4.5.2 or 4.7.2) - https://i.stack.imgur.com/2cqaD.gif – Caius Jard Aug 27 '20 at 07:41
  • @Jimi Yes, but wouldn't that include also `XYZOVS0001#R1XYZ` for example? – MatSnow Aug 27 '20 at 07:48
  • 1
    @MatSnow If that's a possible case, you can close it on the right then: `"ITEM_CODE LIKE '%OVS0001#R1'"`. Or all of it: `"ITEM_CODE LIKE 'OVS0001#R1'"` – Jimi Aug 27 '20 at 07:51
  • @Jimi I mean, it's not the same as `=`. That would still include `XYZOVS0001#R1` for example, wouldn't it? – MatSnow Aug 27 '20 at 08:00
  • @MatSnow IIRC, it would not. – Jimi Aug 27 '20 at 08:07
  • @Jimi OK, I'll stop the discussion here and test it. ;-) – MatSnow Aug 27 '20 at 08:08

0 Answers0