Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
DataTable[] Mydt = new DataTable();
and fill it like :

Mydt[i] = .....
Do you know if such a syntax exist in c# ?

Thanks
Posted

You can define array of table like this
C#
DataTable[] tableArray = new DataTable[10]; // define DataTable array of Size 10

for(int i=0;i<10;i++)
 tableArray[i] = new DataTable();//create new data Table 
 
Share this answer
 
Comments
Suvabrata Roy 3-Jan-13 3:58am    
jibesh you are absolutely right but if you use dataset rather that array I think it would me better.

:)
Jibesh 3-Jan-13 4:02am    
Yes. That's another way of doing it. If I want array of table I usually do not prefer DataSet to avoid the other overheads, unless it requires operations supported by dataset
Suvabrata Roy 3-Jan-13 4:06am    
Exactly :)
Hi
you can use from following code for create dynamic size of Data Table.
in this example you can get size of data table from user by console and create your DataTable and if user enter zero this while loop will be finished.

C#
DataTable[] table;
int n;

while (true)
{
    Console.Write("Please enter size of Data Table: ");
    n = int.Parse(Console.ReadLine());

    if (n == 0)
        break;

    table = new DataTable[n];
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900