如何遍历OleDbDataReader
并将其元素放入ArrayList
?
// ...
ArrayList list = new ArrayList();
while(myReader.Read())
{
foreach(string s in myReader) // I got an Exception here
{
list.Add(s);
}
}
// ...
Label lbl = new Label();
lbl.Text = list[i] as string;
,这里是例外:
System.InvalidCastException: Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.String'.
try this:
while (myReader.Read())
{
list.Add(myReader.GetString(0));
}