C# Programming
03-26-2010, 07:11 AM
I am facing a problem while filtering using the datatable class select function.
Following is the code.
DataTable dt;
DataRow dr ;
dt = New DataTable()
dt.Columns.Add("t", System.Type.GetType("System.String"));
dr = dt.NewRow();
dr["t"] = "12";
dt.Rows.Add(dr);
Dim search As String 'There is no problem when i write the following search string
search = "~!@#$%^&*"
dt.Select("t like '%" + search.Replace("%", "[%]").Replace("'", "''") + "%'");
but problem comes when i append a special character ( with the search
search = "~!@#$%^&*(";
dt.Select("t like '%" + search.Replace("%", "[%]").Replace("'", "''") + "%'");
Error message is
Error in Like operator: the string pattern '%~!@#$[%]^&*(%' is invalid.
Following is the code.
DataTable dt;
DataRow dr ;
dt = New DataTable()
dt.Columns.Add("t", System.Type.GetType("System.String"));
dr = dt.NewRow();
dr["t"] = "12";
dt.Rows.Add(dr);
Dim search As String 'There is no problem when i write the following search string
search = "~!@#$%^&*"
dt.Select("t like '%" + search.Replace("%", "[%]").Replace("'", "''") + "%'");
but problem comes when i append a special character ( with the search
search = "~!@#$%^&*(";
dt.Select("t like '%" + search.Replace("%", "[%]").Replace("'", "''") + "%'");
Error message is
Error in Like operator: the string pattern '%~!@#$[%]^&*(%' is invalid.