How to make if condition logic if datatable doesn't have any data?

Hello, all

I’d like to make logic with If condition like below.
(If there is recommendable activity, please let me know!!)

  1. sometimes ‘ResDT’ contains rows or sometime no rows.
    So, if there is no rows it returns exception error.

  2. Utilize If condition, if there is no row than send log message and else proceed Write range.

To make above logic , how can to design process?

@Dorothy_lee

You can count the number of rows in data table. If the table is empty then it will contain zero rows else it will have more than zero rows

Use this in if condition

ResDT_Out.Rows.Count.Equals(0)

1 Like

@kumar.varun2 Hello !
error is occurred before if condition. should I change order…?

@Dorothy_lee

You need to use the if clause inside the assign activity with the LINQ.

What is the LINQ that you are using inside Assign Activity

1 Like

oh I see.

(From d In ResDT_Ori.AsEnumerable
Let chk1 = St_Arr_keyword.Any(Function (k1) d(“Description”).toString.Trim.Contains(k1))
Let chk2 = St_Arr_keyword3.Any(Function (k2) d(“Outplus”).toString.Trim.Contains(k2))
Where {chk1,chk2}.All(Function (b) b)
Select r=d).CopyToDataTable

@Dorothy_lee

Try this

image

If(
	(From d In ResDT_Ori.AsEnumerable
	Let chk1 = St_Arr_keyword3.Any(Function (k1) d("Description").toString.Trim.Contains(k1))
	Let chk2 = St_Arr_keyword3.Any(Function (k2) d("Outplus").toString.Trim.Contains(k2))
	Where {chk1,chk2}.All(Function (b) b)
	Select r=d).Count.Equals(0),
	_
	Nothing,
	_
	(From d In ResDT_Ori.AsEnumerable
	Let chk1 = St_Arr_keyword3.Any(Function (k1) d("Description").toString.Trim.Contains(k1))
	Let chk2 = St_Arr_keyword3.Any(Function (k2) d("Outplus").toString.Trim.Contains(k2))
	Where {chk1,chk2}.All(Function (b) b)
	Select r=d).CopyToDataTable
)

and for the if Condition use

ResDT_Out is Nothing

1 Like

@Dorothy_lee

Is it working for you?

You need to put your activity inside a Try Catch activity.
If there are no rows, then you will get an Exception.
If you have rows, go ahead.

1 Like

In case there is an option that the result will be empty I use following approach:
1/ I store the result in Array(of DataRow) - array could be empty - using .ToArray method instead of .CopyToDataTable
2/ I check the array.count > 0
3/ if array is not empty I copy array to datatable

Cheers

1 Like

@kumar.varun2 It’s was working well !!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.