I'm developing an application on the datagridview filtering. I'm using RowFilter property of the dataview for the filtering data. My database table contains int & varchar data type fields. And I want to use "LIKE" query in the RowFilter Property for filtering the dataview but the "LIKE" is used only for the string data type and not for int data type. So I want to convert the int
datatype field to the varchar
datatype, but I don't want to alter my table structure. I just want the datatype to be changed temporary for my filtering condition only.
Can anybody help me in resolving this problem?
string colname="ProductID";
string condition="111";
DataView dv = new DataView();
dv.Table = ds.Tables[0] ;
dv.RowFilter ="CAST ("+colname+" AS TEXT) LIKE '"+ condition+"%'" ;
Gets or sets the expression used to filter which rows are viewed in the DataView. public: virtual property System::String ^ RowFilter { System::String ^ get(); void set(System::String ^ value); }; C# Copy.
The DefaultView property returns a DataView you can use to sort, filter, and search a DataTable.
Using a DataView, you can expose the data in a table with different sort orders, and you can filter the data by row state or based on a filter expression. A DataView provides a dynamic view of data in the underlying DataTable: the content, ordering, and membership reflect changes as they occur.
VB.NET ADO.NET DataView Tutorial The DataView provides different views of the data stored in a DataTable. That is we can customize the views of data from a DataTable. DataView can be used to sort, filter, and search the data in a DataTable , additionally we can add new rows and modify the content in a DataTable.
The RowFilter is being carried out by .NET, not SQL Server. It supports a limited set of expressions which are described in the Framework documentation.
http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx
You should be able to use LIKE as well as CONVERT, but unlike SQL server, it wants a .NET type.
dv.RowFilter ="CONVERT("+colname+", System.String) LIKE '"+ condition+"%'" ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With