0

I am looking a way to separate the values in a datatable. So there will be 1 datatable that will hold all the values that the user enters. Then I would like to separate these values based on some conditions. These 2 groups of values will then be transferred over to 2 different datatables where I would send them to other pages( both are not sending to the same page) through session. Right now, I actually stuck as I am not sure how to spilt it up. I have done some research and found that datatable.select could possibly work. Another way is to use LINQ to Datatable like this:

    List<DataTable> result = DTHead.AsEnumerable()
        .GroupBy(row => row.Field<int>("MIVID"))
        .Select(g => g.CopyToDataTable())
        .ToList();

Honestly, I am not too sure which one is good for my application so I decided to bring this to here and ask around. Thanks.

Talon
  • 3
  • 2
  • 5
  • I'm not sure what's the question about. You have working code? If so, what is the problem, it looks very concise and readable, so perfect. If not, what are those conditionas you're talking about? – Tim Schmelter Apr 11 '21 at 10:33
  • If you have the datatable already, pass it over to the pages by filtering with Where in the LINQ. So that there will be no overhead of splitting datatable into multiple tables. – T.kowshik Yedida Apr 11 '21 at 10:33
  • @TimSchmelter my question is that can I split the values in a datatable? If yes then I would like to know firstly how to do it. Secondly, it has to go by some condition e.g. if the dt column contains a certain value, let's say 1, then it will split based on this condition. Thirdly, after splltting, i would like to put them into 2 different tables – Talon Apr 11 '21 at 13:51
  • @T.kowshikYedida I see. Let me try it out and see if works – Talon Apr 11 '21 at 13:52
  • @Talon: your code already shows how to split one table into multiple, you haven't understood? But without more information it's impossible to help. You don't even show an example and a desired result. – Tim Schmelter Apr 11 '21 at 14:01
  • @Talon see this question https://stackoverflow.com/q/9938524/5798300 – T.kowshik Yedida Apr 11 '21 at 16:41
  • I fail to see why not the original UI setup does not present data from the several tables, and I fail to grasp why at save time the data is not saved back to the correct tables? If we display say invoice + invoice details, then top part of the form is one record (the invoice record). Then lower part will be the repeating rows of details from the InvoiceDetails table. Makes no sense to gather information in a UI, and then save out to different tables AFTER. UI in first place should have done so. If you save data and split later it, then you have to re-write the UI two times to edit that data. – Albert D. Kallal Apr 11 '21 at 19:05

0 Answers0