Find Blank Column Using LINQ In UiPath

Working in UiPath Studio is really interesting. Using LINQ saves us so much time with easier steps. 

In this article, we will use two LINQ queries. First one is to get all the column names from a DataTable, and the second one is to identify the blank column in the DataTable. 

Let's begin... 

Step 1 

Open UiPath Studio.

From the Start menu, find Process under New Project column. Click to create a new process. 

Find Blank Column Using LINQ in UiPath

Write a Name and an optional Description for the process. 

Click Create 

Step 2 

First, we will build our DataTable, alternatively, we can take any existing DataTable from any excel or CSV file. 

Find Blank Column Using LINQ in UiPath

Here in the Build Data Table activity, we assign the DataTable to a variable DT of DataTable type. 

We populate the DataTable with dummy data, keeping one column (Column C) blank. 

We will find this blank column using LINQ queries in the next steps. 

Step 3 

Create a variable arrayStr of Array of String from the Variable panel at the bottom. 

Find Blank Column Using LINQ in UiPath

Now take an Assign activity and type the Array variable (arrayStr) to its Left side (To Variable field) 

On the right side (Set Value field) of the Assign activity write the first LINQ query 

DT.Columns.Cast(Of DataColumn).Select(Function(m) m.ColumnName.ToString).ToArray 

Find Blank Column Using LINQ in UiPath

This query gets all the column name of the DataTable DT and puts them into an array which is then assigned to arrayStr array variable. 

Step 4 

Now that we have all the column names in one place, we can check which column is blank and get output accordingly. 

Find Blank Column Using LINQ in UiPath

First, we take a For Each loop and configure it with arrayStr array, as we want to iterate through each item of this array.

Now as each item of this array is a column name of our DataTable, for each column name of this array we want to check if that column is blank. 

We will take a Write Line activity and put our message like this,

currentItem.ToString+": Blank Status = "+(dt.AsEnumerable.All(Function(r) r(currentItem) Is Nothing OrElse String.IsNullOrEmpty(r(currentItem).ToString))).ToString

The first part of the message is the column name, and the last part is checking if the column is blank. The last part returns a Boolean result (True/False) which we have converted as String using ToString method. 

Step 5 

It’s time to run the project.

Click Run from the Ribbon or click Ctrl+F5

Find Blank Column Using LINQ in UiPath

At the output panel at the bottom, we can find our result 

Find Blank Column Using LINQ in UiPath

Summary 

We have taken a DataTable and looked for any blank column in it using LINQ query. In our DataTable there was only one blank column (Column C). The bot found it and got the correct result in the output. 


Similar Articles