Convert ArrayList to DataTable in C#
How to Convert ArrayList to DataTable in C#.
Below is the code snippet to demonstrate how to transfer the data from ArrayList to DataTable in C#. For Example I have one ArrayList and added the Items to arrayList, If I want to send the data from ArrayList to DataTable, below is the solution for that.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
ArrayList MyArrayList = new ArrayList();
MyArrayList.Add("The");
MyArrayList.Add("quick");
MyArrayList.Add("brown");
MyArrayList.Add("fox");
DataTable table = new DataTable("table");
DataColumn column;
DataRow row;
column = new DataColumn();
column.DataType = Type.GetType("System.String");
column.ColumnName = "SyntaxHelp";
table.Columns.Add(column);
foreach (String item in MyArrayList)
{
row = table.NewRow();
row["SyntaxHelp"] = item;
table.Rows.Add(row);
}
}
}
}
hi Naveen Reddy,
it is possible to do reverse?
from data table to array list
thank you.
:)