Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
DataTable dtGetAll = new DataTable();
LoanClass lcls = new LoanClass();
dtGetAll = lcls.Get_AllLoan();
DataTable dtEmpRecord = new DataTable();
DataRow[] drEmp = dtGetAll.Select("empName like '" + txtNameNumber.Text+"%'");


suppose when i enter 'SHEELA' in the txtNameNumber.Text and try filter.its return 0 rows.but in the dataTable dtGetAll has row containing such name.
what will i have to do now...
Posted
Updated 12-May-12 19:45pm
v2

1 solution

its return 0 rows.but in the dataTable dtGetAll has row containing such name.
Above code looks fine, assuming
1. Case sensitivity is turned off or casesensitivity[^] if turned on then the value is exact macth
2. There is a column with name 'empName'

Try this:
C#
DataRow[] drEmp = dtGetAll.Select("[empName] like '" + txtNameNumber.Text.Trim() + "%'");



Alternative:
The problem with the Select method is that it does not return a filtered table object as expected - it returns an array of DataRow objects. Thus you can not directly bind this array to a DataGrid or other data bound controls. Instead try DataView:
C#
dtGetAll.DefaultView.RowFilter = "[empName] LIKE '" + txtNameNumber.Text + "%'";
DataTable dtOutput = dtGetAll.DefaultView.ToTable();

On the filter event, just filter the data using a dataview and then use the filtered dataview as the datasource of your grid.

To know more of it, read here: MSDN: DataView.RowFilter Property[^]
 
Share this answer
 
v2
Comments
VJ Reddy 13-May-12 2:04am    
Good answer. 5!
Sandeep Mewara 13-May-12 2:14am    
Thanks VJ.
Reza Ahmadi 13-May-12 3:25am    
my 5!
Sandeep Mewara 13-May-12 4:34am    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900