public partial class _Default : System.Web.UI.Page
{
string connectionString = "Data Source=LocalHost; Initial CataLog=ERPFinAccounting;
User ID=kris; Password=XXX";
protected void Page_Load(object sender, EventArgs e)
{
ArrayList myArrayList = ConvertDataSetToArrayList();
// Display each item of ArrayList
foreach (Object row in myArrayList)
{
Response.Write(((DataRow)row)["AccountCode"].ToString() + " " + ((DataRow)row)["AccountName"].ToString() + "
");
}
}
}
public ArrayList ConvertDataSetToArrayList()
{
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("Select * from AccountsTable", conn);
cmd.CommandType = CommandType.Text;
conn.Open();
SqlDataAdapter myAdapter = new SqlDataAdapter();
myAdapter.SelectCommand = cmd;
DataSet myDataSet = new DataSet();
myAdapter.Fill(myDataSet);
ArrayList myArrayList = new ArrayList();
foreach (DataRow dtRow in myDataSet.Tables[0].Rows)
{
myArrayList.Add(dtRow);
}
conn.Close();
return myArrayList;
}