How to map Datatables into Array of Datatable

Hello,
I’m trying to map several Datatable into an array of Datatable.
( Type = System.Data.Datatable )

Datatable_array(0) = Datatable_a
Datatable_array(1) = Datatable_b
… etc.

but when I run the program I get the error :
Assign: The object reference was not set to an object instance.

Can you tell me where the error is?

thanks a lot

Scathara

@Scathara1

You know the count of datatables

with x as this number:

  • Initialise your Array:

    Datatable_array = New DataTable(x){}

  • Assign each DataTable:

    Datatable_array(0) = Datatable_a
    Datatable_array(1) = Datatable_b

You don’t know the count

Create a List of DataTable, add each DataTable then convert ToArray if needed.

  • Initialise your list:

    Datatable_list = New List(Of DataTable)

  • Either use the following code or use the AddToCollection activity:

    Datatable_list.Add(Datatable_a)
    Datatable_list.Add(Datatable_b)
    ...

  • Then convert to Array:

    Datatable_array = Datatable_list.ToArray

4 Likes

Hey msan
many thanks for this very detailed and easy to understand answer

Greetings

Scathara

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