Reputation: 918
I have a data table which I was to split as multiple datatables. The structure inside the datatable has three columns
Company Name. Emp Name and Phone
I want to split the whole datatable into multiple datatables each containing all the employees from one company. I hope I am making sense here with my question. I understood linq is the best way to go about doing this, but I have never used linq before and have completely no idea of how to go about doing this.
Can some one give me a lead on how to go about this? Some code example would be highly appreciated.
Thank you
Upvotes: 1
Views: 2446
Reputation: 33381
You can get your company names and data tables as dictionary using this:
Dim dict = dataTable.AsEnumerable().GroupBy(Function(r) r.Field(Of String)("CompanyName")).ToDictionary(Function(g) g.Key, Function(g) CopyToDataTable)
Upvotes: 3