I am trying to extract values from AraryList but all i keep getting is System.Object[]…
protected void Page_Load(object sender, EventArgs e)
{
ReadDb readClass = new ReadDb();
ArrayList list = new ArrayList();
list = readClass.ReadFromDb();
string s = list[4].ToString();
Response.Write(s);
}
EDIT:
public class ReadDb
{
List<string> rowList = new List<string>();
public List<string> ReadFromDb()
{
Database db = new Database();
try
{
using(SqlConnection con = new SqlConnection(db.ConnectionString))
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Blog", con);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
object[] values = new object[reader.FieldCount];
reader.GetValues(values);
rowList.Add(values.ToString());
}
con.Close();
}
}
catch//(SqlException e)
{
}
return rowList;
}
}

Any ideas?
Don’t use
ArrayList, useArray<string>instead. In .NET before 2.0 there were no generics and no way to make type safe collections.ArrayListis one of those original collections from the .NET 1.X times.When writing new code, always use the type safe generic collections instead.
Array<string>(in short form written asstring[]) is such a type.Edit
The problem is in this section of the code:
valuesis an array of objects. TheToString()method ofobject[]doesn’t return the contents of the objects in the array, it just returns the name of the type. You have to change the call tovalues.ToString()into something that formats the values of the retrieved line into a string. For example: