AsifCh Posted September 6, 2005 Posted September 6, 2005 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 {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 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, Quote Asif Raza Ashraf Senior Software Engineer Electronic Solutions Pakistan Islamabad
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.