Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
DataTable[] Mydt = new DataTable();
and fill it like :
 
Mydt[i] = .....
Do you know if such a syntax exist in c# ?
 
Thanks
Posted 2-Jan-13 20:31pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can define array of table like this
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 
  Permalink  
Comments
Suvabrata Roy at 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 at 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 at 3-Jan-13 4:06am
   
Exactly :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
 
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];
}
  Permalink  

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

  Print Answers RSS
0 Dnyaneshwar@Pune 1,300
1 Sergey Alexandrovich Kryukov 667
2 Tadit Dash 350
3 ravikhoda 300
4 Manas Bhardwaj 240
0 Sergey Alexandrovich Kryukov 11,224
1 OriginalGriff 6,897
2 Peter Leow 4,795
3 Abhinav S 3,838
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web04 | 2.8.140421.2 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid