0

I am bring down some test names from a lab. I need to compare those with what I currently have stored to see if I need to update or insert a new record.

The current test name in the db table looks like this HGBA2%' (notice the single quote at the end).

In my code I'm bringing back all the test names from the db. I try to find a match with the incoming test name by doing this:

drs = dt.Select("test_id = " + lstIds[j]);

lstIds[j] contains the incoming test names. This throws an error apparently because it can not handle the single quote in the select. What would be the correct way to look in the existing table to compare them?

Thx. Rut

rut
  • 73
  • 5

1 Answers1

1

I would use Linq-To-DataTable instead:

DataRow[] drs = dt.AsEnumerable()
    .Where(row => row.Field<string>("test_id") == lstIds[j])
    .ToArray();

Using DataTable.Select is just less readable and powerful than LINQ. It is limited.

Here's a workaround if you have to use it, f.e. if it's an old project.

Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939