How to remove all rows with empty,null values

How i can remove all rows, null values ,And with mention the column name
Please suggest me on linq query

Hi @priyachennuru789

If you want to remove the whole row which is empty with the specified column, then you can use the below linQ Expression,

- Assign -> Input_dt = Input_dt.AsEnumerable().Where(Function(X) Not String.IsNullOrEmpty(X("Give the column name here").ToString())).CopyToDataTable()

Hope it helps!!

@priyachennuru789

Assign activity: filteredRows = dtData.AsEnumerable().Where(Function(row) Not row.IsNull("ColumnName")).CopyToDataTable()

This query will remove all rows of specified column is empty

Hope this helps

Hi @priyachennuru789

Try this LINQ Expression:

resultDt = (From row In dt.AsEnumerable()
                   Where Not String.IsNullOrEmpty(row.Field(Of String)("ColumnName"))
                   Select row).CopyToDataTable()

resultDt is of DataType System.Data.DataTable()

Hope it helps!!

Hi @priyachennuru789

use below syntax to get not null rows for particular column

dt=dt.Select("ColumnName <>''").CopytoDataTable()

use below syntax to get not null rows for All column

DataTableName=DataTableName.Rows.Cast(Of DataRow)().Where(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or field.Equals(""))).CopyToDataTable()

whenever a column value is null, an access like rowvar(“colvar”).toString or similar will result in an exception. From a null value a toString cannot be called (NullReferenceException)

when ever a column value is not null but is empty like “” or " "… it is not check and recognized by the only isNull check

So we can combine both checks into:

Assign Activity:

(From d in YourDataTableVar.AsEnumerable
Let chk = isNothing(d("YourColName") OrElse String.IsNullOrEmpty(d("YourColName").toString.Trim)
Where not chk
Select r = d).CopyToDataTable

it will check first if it is null
when it is not null it will check if it is empty and can make use of the toString / String Conversion. Also, it will trim the value to handle " ", " " …

Empty Result we can handle as described here.