Hello,

I'm curious as to what the "key" for a DataTable Row collection is. And if there is a better way of executing what I'm trying to do.

My situation is this. I have a DataTable populated with different data from multiple databases, for the sake of this thread let's say the different columns are: name, ID, and color. Now there are three different colors it can be: colorless, blue, and red. How the program is acting now is that if it finds one item and then finds another item that is the same beyond the color, i.e. blue pies with the ID 15 and colorless pies with the ID 15, then it makes two different rows with this information.

This is not the desired result. What I would like the program to do is look at the DataTable and see if there are any items that match in all but the color then to combine them in one of three ways. If there are two records found and one of the colors are colorless then the other color should be the one displayed with the example above that would mean there would only be a single entry for blue pies with the ID 15, the colorless pies would be ignored. If there are two records both with a color, i.e. blue pies with the ID 15 and red pies with the ID 15, then both colors should be displayed, i.e. red/blue pies with ID 15 would be displayed as one row. Finally if there are three records returned then it should be have the same way as if there were two records returned both with a color.

Now of course this problem isn't as easy as checking the data as it comes in because the method that gets all the information to add the rows to the DataTable gets it one would be row at a time.

How I was planning on executing this check was to do one of two things: A) Use the DataTable.Rows.Contains() method or B) For Each Loop through the DataTable.Rows and when it hits a row that contains the same info, minus the color, then combine it. I know in essence they are the same thing but it's the readability that is different.

So my question which is better and if I was going to go the Rows.Contains path what would the "key" value be?

Also note that this example is a super simplified version of what I'm actually doing so if you need clarification please ask.

Actually, you post your problem like a passage and I don't think any one have that much of extra time to read your whole problem so my suggestion is that please work on your problem and if you get any trouble then post your point of problem. rather than posting your problem as we are here for doing your home work

This isn't a homework assignment but a snag I ran into while working on a project at work. The reason I put so much detail in the question was to try and make sure I didn't leave out anything that would affect a possible solution.

I would rather be given more information about a problem that I needed than not given enough then later find out that the reason that the solution that should have worked didn't because of some minor bit of information that was left out.

But if you have a suggestion on how to shorten my posts with still providing an adequate level of detail or if you could explain what would be an adequate level of detail then I would be more than happy to listen.

This article has been dead for over six months. Start a new discussion instead.