AlexBB

I've got a utility function that computes max and min and other useful info and it takes a DataRowCollection as an argument. My tables are large and I want to send in as an argument a small subset of rows, typically at the very bottom of the table. I cannot figure out how to do it.

If I do table.Select ("***") I end up with a DataRow[] object and it seems there is no way to convert it to a DataRowCollection.

It is C# code.

What shall I do

Thanks.




Re: .NET Framework Data Access and Storage DataRowCollection

Attentater

Dear Alex,

If I understand your post correctly, you want to send a DataRowCollection to a method for processing, and need to place specific Rows from a DataTable into said DataRowCollection.

This might do the trick:

myDataRowCollection.Add(myTable.Rows[0]);

You can of course use an integer to specify the particular row you want to retrieve.

Don't hesitate if I can be of further assistance.

Regards,

Attentater





Re: .NET Framework Data Access and Storage DataRowCollection

Merin Gazell

Loop through your DataRow[ ] array adding to a DataRow collection with each pass.



Re: .NET Framework Data Access and Storage DataRowCollection

TimSE2

Can I ask what the advantage of using a DataRowCollection I would use a generic like List and then you can add/delete as you please, also you can create it from an Array using

Code Snippet
List<DataRow> youInputVar = new List<DataRow>(dataRowArray);





Re: .NET Framework Data Access and Storage DataRowCollection

AlexBB

TimSE2 wrote:

Can I ask what the advantage of using a DataRowCollection I would use a generic like List and then you can add/delete as you please, also you can create it from an Array using

Code Snippet
List<DataRow> youInputVar = new List<DataRow>(dataRowArray);

Thanks to everyone for answering. Thanks to Attentater, Merin Gazell and Tim.

I will most likely start adding the rows. The problem is, and I could have used a different method: copying my large table to a smaller one at a starting index and taking the DataRowCollection of the derivative, that the starting index is not immediately apparent during the execution, The Select statement does the cut off by a DateTime parameter which I know (DateTime.Now.AddMinutes (-5)) but I will have to write some 5 lines of code to find the index of the first row in the subset. There might be anywhere between 1 to 100 records in that timespan perhaps more.

In short I figured if it would take that much effort it would be easier for me to write a MinMax routine myself which I have done numerous times before. I actually may end up doing it.

The reason I went into the "deep end" is that I use this graphics demo and the people who wrote it supplied this utility for their own internal purposes. I am obsessed with making my code more readable and compact. I have trouble controlling it. I thought: perhaps they know what they are doing. Perhaps there is a built in advantage of using the DataRowCollection for this. This is why I spent 15 minutes trying until I ran into an unsurmountable problem. I wanted a SIMPLE solution but perhaps none exists.

Again, many thanks. It was very helpful.