Filtering an empty string in a DataTable

How to filter an empty string in a DataTable?

I need to filter a column (e.g. client name, where string.Empty name)

I tried this, but can't get into the right path.

I need to filter a DataView through DataView.RowFilter .. so how to pass a filter string to string.Empty ..

Any idea on this?

+4
source share
5 answers

To filter dataTable-

 dt.Select("customer_name = ''"); 

To filter data -

 dv.RowFilter = "customer_name = ''"; 
+3
source

Use selection method:

 DataRow[] foundRows = dt.Select("MyColumn = ''"); 
+1
source

You can use the Select method for a DataTable :

 //selects all customers which name is empty var rows = dtData.Select("CustomerName = ''"); 
+1
source

See the code below might help. I answer as the question has a RowFilters tag

 private void GetRowsByFilter() { DataTable table = DataSet1.Tables["YourTable"]; // Presuming the DataTable has a column named Date. string expression = "Column_name = ''"; // Sort descending by column named CompanyName. string sortOrder = "ColumnName DESC"; DataRow[] foundRows; // Use the Select method to find all rows matching the filter. foundRows = table.Select(expression, sortOrder); // Print column 0 of each returned row. for(int i = 0; i < foundRows.Length; i ++) { Console.WriteLine(foundRows[i][0]); } } 
0
source

Try entering the code:

 DataTable dt=new DataTable(); DataRow dr; dr=dt.NewRow(); if(dr["CustomerName"]==null) { put some code here......... } 

i hope this code helps 4 u

0
source

Source: https://habr.com/ru/post/1490642/


All Articles