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:
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
:
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[
^]