Problem in DataSet RowFilter

AsifCh

Regular
Joined
Oct 14, 2003
Messages
59
Location
Islamabad (Pakistan)
Hi,

I am using a datagrid to display the records and a drop down list which contains the column names, a text box to enter the text for search and a button to perform the search. I perform the search on the appropriate column of the data grid by using the dataset's RowFilter property. It is working nice. But now i have a problem that when the user enters a single apostrophe like " ' " in the search filed it gives an error that is like
PHP:
{System.Data.SyntaxErrorException}
    [System.Data.SyntaxErrorException]: {System.Data.SyntaxErrorException}
    HelpLink: Nothing
    InnerException: Nothing
    Message: "The expression contains an invalid string constant: ' ."
    Source: "System.Data"
    StackTrace: "   at System.Data.ExpressionParser.ScanString(Char escape)
   at System.Data.ExpressionParser.Scan()
   at System.Data.ExpressionParser.Parse()
   at System.Data.DataExpression..ctor(String expression, DataTable table, Type type)
   at System.Data.DataView.set_RowFilter(String value)
   at HRA3.ViewCenter.bindGrid() in c:\inetpub\wwwroot\CAO\HRA3\HRA3Forms\ViewCenter.aspx.vb:line 87"
    TargetSite: {System.Reflection.RuntimeMethodInfo}

but if i use the two inverted commas it works just fine. The one solution to this problem is that i ristrict the user to use the Inverted commas but that is not feasible. If any body have any other solution then please share it, However the code to perform the search is
PHP:
If Me.ddlColumnList.SelectedItem.Text.ToString().Trim() <> "" Then
    searchExpression = "Convert([" + Me.ddlColumnList.SelectedItem.Value.ToString() + "], 'System.String') like  '%" + Me.txtSearch.Text + "%' "
End If
MyDataSet.DefaultView.RowFilter = searchExpression
dgCenter.DataSource =MyDataSet.DefaultView

Please give some solution to this problem
I will be thankfull to you.

Regards,
 
Back
Top