Convert ArrayList To DataSet in ASP.Net

ArrayList arraylistcontainer=new ArrayList(3);
arraylistcontainer.Insert(0,”India”);
arraylistcontainer.Insert(1,”USA”);
arraylistcontainer.Insert(2,”Japan”);

public DataSet ConvertArrayListToDataSet()
{
DataSet dsTemp = new DataSet();
DataTable Tables = new DataTable();
dsTemp.Tables.Add(Tables);

dsTemp.Tables[0].Columns.Add(“val”, System.Type.GetType(
“System.String”));

foreach (string str in arraylistcontainer)
{
if (str != string.Empty)
{
DataRow myRow = dsTemp.Tables[0].NewRow();
myRow[0] = str;
dsTemp.Tables[0].Rows.Add(myRow);
}

}
}

Advertisements

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: