c#中的OleDbDataReader转换为ArrayList



如何遍历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));
}

相关内容

  • 没有找到相关文章

最新更新