Assigning multiple datatypes to array

  • Thread starter Thread starter Steve Wasser
  • Start date Start date
S

Steve Wasser

I've got a DataTable, see? I'm pulling it from a stored procedure, dig? I've
gotta push it to an array for calculating certain columns, then spit it to a
web page. With me so far? The datacolumns are dates, doubles, strings, man.
How do I store all the different datatypes in a multidimensional array,
dude? Am I looking at a jagged array? Nope, all answers point to another way
of calulating this drek, right? I'm doing this becuase the Stored Procedure
can't handle the calculation, in case you're wondering why I just don't do
it that way.

I look forward to your answer with anticipation.
 
Steve Wasser said:
I've got a DataTable, see? I'm pulling it from a stored procedure, dig? I've
gotta push it to an array for calculating certain columns, then spit it to a
web page. With me so far? The datacolumns are dates, doubles, strings, man.
How do I store all the different datatypes in a multidimensional array,
dude? Am I looking at a jagged array? Nope, all answers point to another way
of calulating this drek, right? I'm doing this becuase the Stored Procedure
can't handle the calculation, in case you're wondering why I just don't do
it that way.

Just use an array of type object - I don't see why you need a
multidimensional array though.
 
I was just assuming I'd need a [,] array for rows and colums. I'll need to
cherry-pick the columns I want to add (like the 3rd, 4th, 5th columns will
be summed, all others will left alone) To do that, I would have to reference
a specific column/row, wouldn't I?
 
Steve Wasser said:
I was just assuming I'd need a [,] array for rows and colums. I'll need to
cherry-pick the columns I want to add (like the 3rd, 4th, 5th columns will
be summed, all others will left alone) To do that, I would have to reference
a specific column/row, wouldn't I?

Well then, why not just iterate through the rows of original datatable?
All the facility you need - iterating, indexing, modifying, is all there
already.

If you're going to create extra data structures, use them to store the
results of your calculations, and not data that is already contained in the
datatable.

Erik
 
Steve Wasser said:
I was just assuming I'd need a [,] array for rows and colums. I'll need to
cherry-pick the columns I want to add (like the 3rd, 4th, 5th columns will
be summed, all others will left alone) To do that, I would have to reference
a specific column/row, wouldn't I?

But, if you do want to push out all your datarows to an array, you
probably want to use the DataRow.ItemArray property, which returns an array
of type object, as Jon Skeet suggested.

Erik
 
Two options are best,
You can either create a custom collection class of that table using only the fields you are interested in or, can create a DataTable, and then iterate through its rows or columns which ever you are working with.
Jagged arrays are not the best solution for this.

Hope this might work!
 
Three freaking books, and not one of them mentions the existence of a
DataRow.ItemArray property...thanks for your help, guys.

--
Steve Wasser
http://xdissent.com
the journal of contrarian social discourse and neurotic opinion
Erik Frey said:
Steve Wasser said:
I was just assuming I'd need a [,] array for rows and colums. I'll need to
cherry-pick the columns I want to add (like the 3rd, 4th, 5th columns will
be summed, all others will left alone) To do that, I would have to reference
a specific column/row, wouldn't I?

But, if you do want to push out all your datarows to an array, you
probably want to use the DataRow.ItemArray property, which returns an array
of type object, as Jon Skeet suggested.

Erik
 
Back
Top