如何迭代通過OleDbDataReader
並將其元素放入ArrayList
?OleDbDataReader以ArrayList在C#
這裏是我的代碼:
// ...
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'.
我不明白這一點。你想做什麼?將所有可用列中的字符串放入列表中,而不考慮列名或類型? – GSerg 2011-12-17 12:27:07