Convert datatable/dataset to arraylist in asp.net MVC in C#

Convert datatable/dataset to arraylist in asp.net MVC in C#

 

public ArrayList ConvertDatasettoArrayList()
{
DataSet ds = new DataSet();
ArrayList list=new ArrayList();
using (SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=TestDB;Integrated Security=true"))
{
using (SqlCommand cmd = new SqlCommand("select * from EmpInformation", con))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);

foreach (DataRow dtrow in ds.Tables[0].Rows)
{
list.Add(dtrow);
}
}
}
return list;
}


//////////////////////////////////////

public ArrayList ConvertDataTabletoArrayList()
{
DataTable dt = new DataTable();
ArrayList list = new ArrayList();
using (SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=TestDB;Integrated Security=true"))
{
using (SqlCommand cmd = new SqlCommand("select * from EmpInformation", con))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);

foreach (DataRow dtrow in dt.Rows)
{
list.Add(dtrow);
}
}
}
return list;
}

2021-10-03