VB.NET - How to convert IEnumerable to DataTable in VB.Net without using looping

Asked By Sivanesh Vanmeeganathan on 27-Feb-14 04:09 AM
I used this code
Dim orgCustomers = From rw In ds.Tables(0).AsEnumerable()
                                        Group rw By grpId = rw.Field(Of String)("CustomerID") Into Group
                                        Where (Group.Count() = 1 Or Group.Count > 1)
                                        Select (Function(g) g.Key)

how to convert orgCustomers to DataTable.
I tried this one also, (not working)
Dim ttd As DataTable = chtView.AsEnumerable()
this also, (not working)
Dim tb As DataTable = CType(orgCustomers, DataTable)

but i cannot use looping statements because it makes slow process
Robbe Morris replied to Sivanesh Vanmeeganathan on 27-Feb-14 08:15 AM
The LINQ query you've got here to extract records from the DataTable is slower than whatever loop you intend to run to recreate a new DataTable from it.    I'd rethink my whole strategy on this.
Sivanesh Vanmeeganathan replied to Robbe Morris on 28-Feb-14 12:34 AM
ok, i will thanks
Sivanesh Vanmeeganathan replied to Robbe Morris on 28-Feb-14 07:05 AM
Any idea for how to remove duplicate rows based on one column from DataSet.
Sivanesh Vanmeeganathan replied to Sivanesh Vanmeeganathan on 03-Mar-14 12:15 AM
Without loop i can't
So i used like this.
Dim orgCustomers1 = (From rw In ds.Tables(0).AsEnumerable()
                                                        Group rw By grpId = rw.Field(Of String)("CustomerID") Into Group
                                                        Where (Group.Count > 1)
                                                        Select Group)
                                   
                                    'HERE REMOVING DUPLICATE
                                    For Each drr1() As DataRow In orgCustomers1
                                        If drr1.Length > 1 Then
                                            ds.Tables(0).Rows.Remove(drr1(drr1.Length - 1))
                                        End If
                                    Next