Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, there are many ways to add two ArrayList instances to one DataTable instance. Here is one way that shows how to add any number of ArrayLists to one DataTable using a complete code sample compiled to the .NET Framework 2.0.</p> <p><em>Note</em>: Other people are doing a good job trying decipher what you're up to - I'm just going to answer the question directly with a full code snippet in case you can gain any insights from it for yourself.</p> <p>This really isn't a complex answer - it just sets up a couple of ArrayList instances first with sample data to pertain to your question and provides a snippet at the end to test the solution. </p> <p>Please comment what insights you find in here, if any. Thank you.</p> <pre><code>namespace Com.StackOverflow { using System.Diagnostics; using System.Data; using System.Collections; public static class SOQuestion__Add_two_arraylists_in_a_datatable { public static void AnswerQuestionDirectly() { // - - - - - - - - Prelimary setup to question - - - - - - - - // Sample list of filenames (3 elements in total). ArrayList listFilenames = new ArrayList( new[] {@"C:\a.dat", @"C:\b.dat", @"C:\c.dat"} ); // Sample list of error counts (2 elements in total). ArrayList listFailureCounts = new ArrayList( new[] {88,51} ); // - - - - - - A Direct answer to the question - - - - - - - // Create DataTable structure with one column. DataTable dTable = new DataTable(); dTable.Columns.Add("Column 1"); /* Populate DataTable with all lists at once. * Note: keep appending * to { array initialization list } all lists you want included * in the DataTable instance. */ foreach (ArrayList currentList in new[] { listFilenames, listFailureCounts }) { foreach (object element in currentList) dTable.Rows.Add(new[] { element }); // one column per row } // - - - - - - - - Test it for expected counts - - - - - - - - int totalExpected = listFilenames.Count + listFailureCounts.Count; //Verify DataTable contains the same amount of rows. Debug.Assert(dTable.Rows.Count == totalExpected); } } } </code></pre> <p>The above answer can be copied and pasted into a .cs file and run with the following code: <code>using Com.StackOverflow;</code> .</p> <pre><code>SOQuestion__Add_two_arraylists_in_a_datatable.AnswerQuestionDirectly(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload