我正在尝试将数据从FbDataReader推入ArrayList。这是我的示例代码:

ArrayList aList = new ArrayList();
FbCommand fbCommand = new FbCommand("SELECT * FROM users", dbConn);
FbDataReader fbDataReader = fbCommand.ExecuteReader();
while (fbDataReader.Read()) {
    aList.Add(fbDataReader[0]);
    // Should push all the fbDataReader (including rows and columns) into the aList array
}
fbDataReader.Close();
return aList;

最佳答案

不要在代码中添加问题。这使得它很难找到。

您可以从接口GetValues()(数据读取器实现)的接口中使用方法IDataRecord

public IList<object[]> FindUsers()
{
    using (var command = dbConn.CreateCommand())
    {
        command.CommandText =  "SELECT * FROM users";
        using (var reader = command.ExecuteReader())
        {
            var rows = new List<object[]>();
            while (reader.Read())
            {
                var columns = new object[reader.FieldCount];
                reader.GetValues(columns);
                rows.Add(columns);
            }
            return rows;
        }
    }
}


允许您以后使用:

var users = FindUsers();
var value = users[rowIndex][columnIndex].ToString();

关于c# - FbDataReader到C#中的ArrayList,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8815542/

10-11 05:51