Hi All,
I have this great little snippet of code that I bind to a Datalist with no problem.
When I go to trace out individual values of the arraylist , I get all sorts of errors.
I am populating the arraylist with a sqldatareader result set. Unfortunately I can find very little helpful information on this class “System.Data.Common.DbDataRecord”. I just can’t seem to access individual values.
Any help would be greatly appreciated!
Thanks,
Nathan
(Notice my commented notes within the code)
public ArrayList GetSQLDataReaderAryLst(string sqlString)
{
// sqlString = “select mid, MediaTitle, LastName from Media”
SqlConnection conn = new SqlConnection(_connStr);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = sqlString;
conn.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
ArrayList ar = new ArrayList();
foreach (System.Data.Common.DbDataRecord ddr in dr)
{
ar.Add(ddr);
}
// my problems are here below:
// I’m trying to grab the first row value where the column equals “MediaTitle”
string passMsg = ((ddr)ar[0]).MediaTitle.ToString();
Trace.Warn("one value:", passMsg);
conn.Dispose();
// the arraylist binds fine to the datalist
return ar;
//dataGridView1.DataSource = ar; // this is the end result
}
I have this great little snippet of code that I bind to a Datalist with no problem.
When I go to trace out individual values of the arraylist , I get all sorts of errors.
I am populating the arraylist with a sqldatareader result set. Unfortunately I can find very little helpful information on this class “System.Data.Common.DbDataRecord”. I just can’t seem to access individual values.
Any help would be greatly appreciated!
Thanks,
Nathan
(Notice my commented notes within the code)
public ArrayList GetSQLDataReaderAryLst(string sqlString)
{
// sqlString = “select mid, MediaTitle, LastName from Media”
SqlConnection conn = new SqlConnection(_connStr);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = sqlString;
conn.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
ArrayList ar = new ArrayList();
foreach (System.Data.Common.DbDataRecord ddr in dr)
{
ar.Add(ddr);
}
// my problems are here below:
// I’m trying to grab the first row value where the column equals “MediaTitle”
string passMsg = ((ddr)ar[0]).MediaTitle.ToString();
Trace.Warn("one value:", passMsg);
conn.Dispose();
// the arraylist binds fine to the datalist
return ar;
//dataGridView1.DataSource = ar; // this is the end result
}