0

I want to populate generic array(T[]) using ado.net.

Below is my generic array :

T[];

I dont want to use datatable as it is havier as compared to array or list and generic array in turnis lighter and faster than list.

My table structure is like below :

Id     Amount
1      100
2      200
3      300

Moreover i dont want to fill datatable and then loop on to datatable and then filling my generic array.

I know i can use IdataReader and then loop While(dr.read) then fill my generic array.

I am looking for a way like how data adapter is directly filling datatable(da.fill(dt)).

Is there any way to do this?

I Love Stackoverflow
  • 6,738
  • 20
  • 97
  • 216
  • 2
    If you can only use `ADO.NET`, there isn't (or I am not aware of it) any similar way like the `DataAdapter` `Fill ` method. If you can make use for instance Dapper, this is fairly easy (https://github.com/StackExchange/Dapper). – Christos Feb 01 '18 at 06:08
  • I agree with Christos - Dapper seems like the obvious choice for this. it's Light-weight and super fast. – Zohar Peled Feb 01 '18 at 07:14
  • MSDN has a C# example [Retrieving Data Using a DataReader](https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/retrieving-data-using-a-datareader). Another example: [Read data from SqlDataReader](https://stackoverflow.com/q/4018114/4116017) There is nothing fancy there. – Vladimir Baranov Feb 10 '18 at 11:10

0 Answers0