Hello Everyone,
I am trying to delete empty rows from DataTable - “DT” initialized as shown in below screenshot,
I have written code as below using LINQ Cast function,
(From row In DT
From col In DT.Columns.Cast(Of DataColumn)
Where Not String.IsNullOrEmpty(row(col).ToString)
Select row
).CopyToDataTable
But, this giving me error as,
Am i missing anything?
vrdabberu
(Varunraj Dabberu)
January 28, 2024, 6:00am
2
Hi @NILESH.BOT369
Can you try the below syntax:
(From row In DT.AsEnumerable()
From col In DT.Columns.Cast(Of DataColumn)()
Where Not String.IsNullOrEmpty(DirectCast(row(col), String))
Select row
).CopyToDataTable()
Regards
Hi @vrdabberu , thank you for your response,
Its still giving the error,
vrdabberu
(Varunraj Dabberu)
January 28, 2024, 6:09am
5
Hi @NILESH.BOT369
Can you try the below syntax:
DT.AsEnumerable().Where(Function(row) Not row.ItemArray.All(Function(cell) cell Is DBNull.Value OrElse cell.Equals(""))).CopyToDataTable()
Input:
Output:
Regards
2 Likes
Great, this works Perfect!, Appreciate, thank you.
1 Like
vrdabberu
(Varunraj Dabberu)
January 28, 2024, 6:31am
7
You’re welcome @NILESH.BOT369
Happy Automation!!
1 Like
system
(system)
Closed
January 31, 2024, 6:32am
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.