需要您在下面的帮助。在C中字符串中转义特殊字符#
我有代码,我检查数据表中是否存在特定的行;如果行不存在,那么我将该行添加到数据表中。这是工作正常,但行失败时,包含特殊字符链接'
(单引号)失败。
下面是代码:当姓氏包含单引号
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.
此代码失败。
我需要一个解决方案,我不会从姓氏中删除引号。
感谢
此代码正在Web窗体上运行? –
是的,它的网页形式 – user1717270
你的意思是这个代码dgRow.Cells [2] .Text包含引号? –