Assign: The source contains no DataRows?

Now i use assign as below.

dt_inputFile.AsEnumerable.Where(Function(row) CInt(row(in_Config(“Text_FYP”).ToString).ToString) < CInt(CurrentRow(“Rate2”).ToString) And
CInt(row(in_Config(“Text_FYP”).ToString).ToString) > CInt(CurrentRow(“Rate”).ToString)).CopyToDataTable

old file have 2 row as below.

But Now I insert row3 as below.

It show error.
Assign: The source contains no DataRows.

My flow as below.

Please guide about it.

we can apply following pattern:

Result | List(Of Datarows) = dt_inputFile.AsEnumerable()…).ToList

then based on the filter result we can copy it to a datatable or clone the origin one
check within an if acitvity
Result.Count > 0
Then: dtResult = Result.CopyToDataTable
Else: dt_= dt_inputFile.Clone

instead of copytodatatable (throwing the exception) we return a list and do checking the result.count

Hi @fairymemay ,

The condition you have used to filter with has returned zero results, and the error you have encountered is due to the DataTable not willing to take null for a value.

I would recommend appending a .ToList and check if it contains rows before copying it to a DataTable:

dt_inputFile.AsEnumerable.Where(Function(row) CInt(row(in_Config(“Text_FYP”).ToString).ToString) < CInt(CurrentRow(“Rate2”).ToString) And
CInt(row(in_Config(“Text_FYP”).ToString).ToString) > CInt(CurrentRow(“Rate”).ToString)).ToList()

If

lst.Count()>0

Then->

dt_inputFile.AsEnumerable.Where(Function(row) CInt(row(in_Config(“Text_FYP”).ToString).ToString) < CInt(CurrentRow(“Rate2”).ToString) And
CInt(row(in_Config(“Text_FYP”).ToString).ToString) > CInt(CurrentRow(“Rate”).ToString)).CopyToDataTable

Kind Regards,
Ashwin A.K

1 Like

@ashwin.ashok

I would recommend appending a .ToList and check if it contains rows before copying it to a DataTable:

What type in variable assign ?

Hi @fairymemay ,

Here are some screenshots to help you out:

image

image

Kind Regards,
Ashwin A.K

as done here:

@ppr @ashwin.ashok Output not correct.

Data in row3 show output wrong (Now output same row2)


How to solve it ?

Hi @fairymemay ,

Would you be so kind as to elaborate on the issue?

From what I’ve understood so far, you were trying to filter the DataTable on two conditions, which none of the row items met, which is why it outputted an empty List, correct?

Are you trying to say there there are row items that should meet the condition, but the program wasn’t able to detect?

Kind Regards,
Ashwin A.K

@ashwin.ashok @Ramya_K I want to read column Plan Code as below.

image

File input.xlsx (9.8 KB)

And file Config as below.
Config_Leads Propensity.xlsx (15.6 KB)

I want file output as below.
File Output.xlsx (13.0 KB)

1.Compare rate from file input (Column FYP) with file config
2. write datarow in sheet (Follow name column config Sheet)
3. read column Count from file input and write in column Premium (จำกัด 1 รายการ/ท่าน)

Please guide me about it.

Now my flow as below.
Sequence4.xaml (21.6 KB)

Hi @fairymemay ,

Could you give this a try and see if it works out for you?

First, you have to declare a Dictionary(Of String, Tuple(Of Double, Double, Integer))

dt_configRate.AsEnumerable().ToDictionary(Function(k) k("Premium").ToString,Function(v) Tuple.Create(Convert.ToDouble(v("Rate").ToString.Replace(",","")),Convert.ToDouble(v("Rate2").ToString.Replace(",","")),CInt(v("Count").ToString)))

Next, you have to loop through each column value in the Configuration File and create a sheet in an Excel.

Collection of Sheets->

Enumerable.Range(0,dt_configRate.RowCount).Select(Function(s) dt_configRate.Rows(s)(0).ToString).ToArray()

Next, we have to populate a List of DataRows to check if the values are present or not before we copy them to a DataTable →

(From row  In dt_sampleData.AsEnumerable()
Where dict(sheet).Item1<= Convert.ToDouble(row("FYP").ToString.Replace(",","")) AndAlso
			dict(sheet).Item2 >= Convert.ToDouble(row("FYP").ToString.Replace(",",""))
Let ra = row.ItemArray.Take(2).Append(dict(sheet).Item3).Concat(row.ItemArray.Skip(3).ToArray()).ToArray()
Select dt_result.Rows.Add(ra)).ToList()

If so, then the ToList() to replaced with CopyToDataTable(), and if not, then we simply clone the original table(to get the headers) and add a Sheet there.

image

CreateSheetsAndSegregrateOnRates.xaml (11.7 KB)

Kind Regards,
Ashwin A.K
.

1 Like

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