0

如何遍历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'.
4

1 回答 1

1

试试这个:

while (myReader.Read())
{
  list.Add(myReader.GetString(0));
}
于 2011-12-17T12:24:17.447 回答