Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatable Select() Method

I have a Datagridview and the Data Source is dtCustomer I just want to filter the content of grid view based on a search text. Itried the following code

DataTable dtSearch =  dtCustomer;
dtSearch.Select("cust_Name like '" + txtSearch.Text + "%'");
grvCustomer.DataSource = dtSearch;

But this is not working. If any body knows the solution please share.

like image 387
Nithesh Narayanan Avatar asked Oct 20 '11 12:10

Nithesh Narayanan


3 Answers

Try this:

dtSearch.DefaultView.RowFilter = "cust_Name like '" + txtSearch.Text + "%'";  

And check whatever there is space to be removed by triming the text.

like image 105
Boomer Avatar answered Oct 27 '22 07:10

Boomer


Or Try this;

dataGridView.Datasource = datatable.Select("....").CopyToDataTable()
like image 28
Delog Avatar answered Oct 27 '22 07:10

Delog


You can do something like this.

DataView dv1 = dtDefault.DefaultView; 
dv1.RowFilter = "CusGroupId=1 and CustomerCode LIKE '"+txtCustomer.Text +"%'";  
DataTable dt=dv1.ToTable();
like image 23
Example Avatar answered Oct 27 '22 06:10

Example