Fill an array (or arraylist) from SqlDataReader

前端 未结 7 568
滥情空心
滥情空心 2020-12-01 05:36

Is there a way to fill an array via a SqlDataReader (or any other C# ADO.NET object) without looping through all the items? I have a query that is returning a single column

7条回答
  •  青春惊慌失措
    2020-12-01 05:55

    Apparently, ever since .NET 1.1 SqlDataReader had the following method:

    int size;
    object[] data = new object[]{};
    size = reader.GetValues(data);
    

    This populates data with the values of the current reader row, assigning into size the number of objects that were put into the array.

提交回复
热议问题