ArrayList to DataTable

Posted: June 2, 2015 in Arraylist, C#, Collections, DataTable

Below is the simple script to a collection (arraylist – > DataTable) :


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;

namespace Datatable
class Program
static void Main(string[] args)
ArrayList al = new ArrayList();

// Create new DataTable.
DataTable table = new DataTable(“table”);

// Declare DataColumn and DataRow variables.
DataColumn column;
DataRow row;

// Create column.
column = new DataColumn();
column.DataType = Type.GetType(“System.String”);
column.ColumnName = “item”;

// Add items from ArrayList to DataTable.
foreach (String item in al)
row = table.NewRow();
row[“item”] = item;



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s