Need your help in below.
I have code where I am checking that a particular row exists in datatable or not; if row doesn't exist then I add that row to datatable. This is working fine however failing when row value contains special char link '
(single quote).
Below is the code:
string lastName = dgRow.Cells[2].Text.Replace("amp;", "");
DataRow[] dr = dt.Select("LastName='" + lastName + "'"); //check whether row is available in datatable or not
if (dr.Length <= 0)// Condition to check if row is there in data table
{
dt.Rows.Add();
dt.Rows[dt.Rows.Count - 1]["FirstName"] = dgRow.Cells[1].Text;
dt.Rows[dt.Rows.Count - 1]["LastName"] = dgRow.Cells[2].Text;
dt.AcceptChanges();
}
return dt; //Return modified data table to calling function.
This code fails when LastName contains single quotes.
I need a solution where I am not removing quotes from last name.
Thanks