Results 1 to 3 of 3

Thread: [RESOLVED] Array List of Data Tables

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Resolved [RESOLVED] Array List of Data Tables

    Is it possible to create an array list of datatables?

    I have a function that I want to loop through the datatables in my datasets, however I need to know in what order, for this I thought if I could populate the array with the datatables I could then loop through that. However i cannot seem to add a datatable to an arraylist.
    Code:
     public static ArrayList[] sheetDataMappings = new ArrayList[1];
            public static ArrayList[] sheetColumnMappings = new ArrayList[1];
            public static ArrayList[] sheetFunctionMappings = new ArrayList[1];
    
               
            public static ArrayList columnMappings = new ArrayList(9);
            public static ArrayList sheettableMappings = new ArrayList(1);        
            public static ArrayList functionMappings = new ArrayList(1);
            public static DataTable datatable1;
            static ThisReport()
        { 
            
            
           columnMappings.Add(new ColumnMapping("audit_id", 1));
           columnMappings.Add(new ColumnMapping("audit_date", 2));
           columnMappings.Add(new ColumnMapping("duration", 3));
           columnMappings.Add(new ColumnMapping("report_name", 4));
           columnMappings.Add(new ColumnMapping("username", 5));
           columnMappings.Add(new ColumnMapping("parameters", 6));
           columnMappings.Add(new ColumnMapping("version_client", 7));
           columnMappings.Add(new ColumnMapping("version_server", 8));
           columnMappings.Add(new ColumnMapping("status", 9));
           sheetColumnMappings[0] = columnMappings;
           sheetFunctionMappings[0] = functionMappings;
    
           datatable1 = (DataTable)Globals.ThisWorkbook.ds.UP_CRSUsageAudit;
           sheetColumnMappings[0] = datatable1;
        }

  2. #2

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Array List of Data Tables

    Fixed, apparently works with an array but not an array list.

    Code:
    ReportRender.GenericDrawRoutine((Excel.Worksheet)newWorkbook.Worksheets[ThisReport.Sheets[i, 0]], ThisReport.datatables[i], ThisReport.sheetColumnMappings[i], ThisReport.sheetFunctionMappings[i], ThisReport.Sheets[i, 1]);

    Code:
     public static DataTable[] datatables = new DataTable[1];
            static ThisReport()
        { 
            
            
           columnMappings.Add(new ColumnMapping("audit_id", 1));
           columnMappings.Add(new ColumnMapping("audit_date", 2));
           columnMappings.Add(new ColumnMapping("duration", 3));
           columnMappings.Add(new ColumnMapping("report_name", 4));
           columnMappings.Add(new ColumnMapping("username", 5));
           columnMappings.Add(new ColumnMapping("parameters", 6));
           columnMappings.Add(new ColumnMapping("version_client", 7));
           columnMappings.Add(new ColumnMapping("version_server", 8));
           columnMappings.Add(new ColumnMapping("status", 9));
           sheetColumnMappings[0] = columnMappings;
           sheetFunctionMappings[0] = functionMappings;
    
           datatables[0] = (DataTable)Globals.ThisWorkbook.ds.UP_CRSUsageAudit;

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] Array List of Data Tables

    First up, if you're not using .NET 1.x then you shouldn't be using an ArrayList at all. Secondly, you could do it with a collection rather than an array if you do it properly. Remember that collections are specifically designed to grow and shrink dynamically, while arrays are fixed-size. When you create an array it already has all its elements, but they are all empty, like an egg carton. That means that you can set any specific element that you want. With a collection, if you specify a capacity when you create it, that is only a capacity, NOT a size. That is the number of items you can add before the collection must reallocate space internally. The size is still zero to begin with. If the collection has zero items then you can't set an item at a specific index, because there is no such item. You need to call Add on the collection to add a new item. Once an item exists at an index, then you can set it to a new value.

    That said, the whole point of collections is to provide array-like behaviour with dynamic resizing. If you know exactly what size your list is then you should be using an array anyway. A collection uses an array internally anyway so using one directly is always going to be more efficient if you don't need the convenience of dynamic resizing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width