2

So I have an IBindingList which I have as the data source of a DevExpress chart. It is done this way as the chart updates automatically as the data is gathered.

But instead of creating a separate DataTable and logging the data within that I'd prefer if I could use the IBindingList and convert this and the end of the logging to a source that I can bulk insert into a database.

Most methods that I have seen are recursive apart from the FastMember package but I cannot for the life of me convert an IbindingList to a IEnumerable.

Does anyone have any ideas on this to improve the efficiency of the above?

Ɖiamond ǤeezeƦ
  • 3,223
  • 3
  • 28
  • 40
G Short
  • 21
  • 1
  • Can you show the relevant code? What data storage is behind the IBindingList ? – TaW Sep 13 '16 at 11:54
  • I'm confused... [IBindingList inherits IEnumerable.](https://msdn.microsoft.com/en-us/library/system.componentmodel.ibindinglist(v=vs.110).aspx). By definition any IBindingList is also an IEnumerable.... – Jeff B Sep 13 '16 at 12:51
  • Please see this snippet - http://pastebin.com/04d6STb2 It should give you an idea what is going on. I thought as IBindingList inherits IEnumberable I would be able to cast it as an IEnumerable but I couldn't. This was the FastMember post I referenced when attempting it previously - http://stackoverflow.com/questions/564366/convert-generic-list-enumerable-to-datatable – G Short Sep 15 '16 at 07:15

1 Answers1

0

According to Microsoft, IBindingList supports direct conversion to DataTable through extensions methods:

CopyToDataTable<T>(IEnumerable<T>)

Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

Copies DataRow objects to the specified DataTable, given an input IEnumerable object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

Copies DataRow objects to the specified DataTable, given an input IEnumerable object where the generic parameter T is DataRow.

Boris Zinchenko
  • 2,142
  • 1
  • 24
  • 34