G
Guest
I am adding data to a DateTable in a DataSet and need to verify if a row
already exists with a specific column value:
string aName = "O'Connor";
string filter = "Name='" + aName + "'";
DataRow [] drs = MyDataset.MyTable.Select(filter);
if( drs.Length == 0 ) {
// Add a row for this name
}
Note the name (O'Connor) contains a single quote.
How should I escape the aName value so the filter works?
Disclaimers:
1. This is a select on a DataTable not a database select -- so no
parameterized queries.
2. The table MyDataset.MyTable already has a primary key on another field,
so I can't do a MyTable.FindByXXX
already exists with a specific column value:
string aName = "O'Connor";
string filter = "Name='" + aName + "'";
DataRow [] drs = MyDataset.MyTable.Select(filter);
if( drs.Length == 0 ) {
// Add a row for this name
}
Note the name (O'Connor) contains a single quote.
How should I escape the aName value so the filter works?
Disclaimers:
1. This is a select on a DataTable not a database select -- so no
parameterized queries.
2. The table MyDataset.MyTable already has a primary key on another field,
so I can't do a MyTable.FindByXXX