Datatables

forum

#1

Hi,

I have a CSV file that has 550 columns I want split this to 10 tables. How can we create multiple data tables from single table. Please help


#2

Hi @ssk,

it depends on how you want them split? Do these need to split by certain row increments or by column increments.

e.g. columns A - D and then D-F etc OR all columns but rows 1-10 and then 11-20 etc.?

Either way I would possibly using a looped read range to read into separate datatables.

A brief google for “VBnet split datatables” shows several possible answers if you are looking for a code answer.

Thanks


#3

You can place an if condition with rows.count<50,<100 … and build datatable with those values
@ssk


#4

Hi @ssk,

Refer this link

private static List<DataTable> SplitTable(DataTable originalTable, int batchSize)
{
     List<DataTable> tables = new List<DataTable>();
     int i = 0;
     int j = 1;
    DataTable newDt = originalTable.Clone();
   newDt.TableName = "Table_" + j;
   newDt.Clear();
    foreach (DataRow row in originalTable.Rows)
    {
         DataRow newRow = newDt.NewRow();
         newRow.ItemArray = row.ItemArray;
         newDt.Rows.Add(newRow);
         i++;
         if (i == batchSize)
        {
           tables.Add(newDt);
           j++;
          newDt = originalTable.Clone();
          newDt.TableName = "Table_" + j;
          newDt.Clear();
          i = 0;
      }
  }
   return tables;
}

Regards,
Arivu


#5

Hi
I want to split by 50 columns in each data table and I want to do this in UiPath


#6

Thanks for your reply. I want to do this in UiPath


#7

Thanks for reply. I want split in UiPath by column and rows. Like 50 columns and all rows for that columns in a data table.


#8

I have given the process to do itin uipath only using FOr each row,if condition,builddatatable


#9

Hi @ssk,

Yes Its possible follow the same steps in the uipath.

Regards,
Arivu


#10

Thanks again. I am new to UiPath so finding it difficult.


#11

With builddata table I was able to create a table with 7 columns but adding data to those columns from source which has 550 columns is the issue. If I use for each row it will get a row will all 550 columns instead of 7 column rows.


#12

Thanks again. I am new to UiPath so finding it difficult to put same thing in UiPath code. I tried using select for getting only few columns but that returns DataRow() and not sure how to declare the DataRow array


#13

@ssk

Let us take your datatable as dta.
Let us take List of Columns Names List A

ListA=(From p in dta.Columns.CastOf(System.Data.DataColumns)
Select Convert.ToString(p.ColumnName)).ToList

Then Initialise two Integer Variables
intn=0
intk =1

Now You take the inta =ListA.Count/Int Tables
int Tables The number of Tables you want to Create (For your scenario it will be 10)
Create one more datatable dtb
Then Run While loop by giving Condition(K<=int Tables)
Inside while loop
add one if condition
IsNothing(dtb)
If False Then use Clear DataTable to clear dtb

Now use below Query to take the columns from a datatable in an incremental Order.

dtb=dta.DefaultView.ToTable(False,ListA.AsEnumerable.Skip(n*inta).Take(inta).ToArray())

then Increment int n= intn+1 and int K = int K+1

Then use Write Range to Write the DataTable dtb
Give the Sheet Name “Sheet”+intK.ToString

Regards,
Mahesh


#14

Thank you will try this


#15

Datatable Results_of_two_cols = Yourdatatable.Select().CopyToDataTable().DefaultView.ToTable(False, “Date”, “Close”)
this worked perfectly


#16

@ssk

You told to create 50 Seperate tables with 10 columns each right.

Regards,
Mahesh


#17

yes I modified the above code as per my requirement. I got this one from one of the forum.

Thanks,
Siva