views:

107

answers:

3

Is it possible to provide datatable rows with names in string form as one does with columns? I want to be able to refer to a row via a name rather than an index.

EDIT: My bad. I am working in C#. I should have stated that.

I am doing market correlation studies using statistical analysis. I want to store the outputs of correlation studies in a dataTable. Each column is a market that is included in the studies. The rows would have the same names as the columns in the same order. So I would place the output of a correlation study between the Gold market and the Copper market at the intersection of the Column "Gold" and the Row "Copper" (as well as at the intersection of the Column "Copper" and Row "Gold").

In order to easily refer to the outputs of these studies elsewhere in my code, I want to be able to refer to the rows by market name rather than by index.

Thanks!

A: 

I have no idea what database you're using, but I don't think there's a way to do this. In Oracle there's something kind of similar called a rowid (a unique id per row, independent of a primary key), but I'm not sure if other databases have the same thing.

Alex Beardsley
A: 

Would something as simple as an Enum for your row/column names help here?

kristian
A: 

I'll go out on a limb here and suggest that the table structure you are using may not be the best one for storing your results. One reason is that it is not easily extensible - you have to physically modify the table if you add/subtract the markets that you are recording correlation for.

I see a better structure for holding the data as:

ID | Market1 | Market2 | Correlation
------------------------------------
 1 | Gold    |  Silver |  0.8
 2 | Gold    |  Bronze |  0.5
 3 | Silver  |  Bronze |  0.1
 etc

 With a Primary Key (PK) on (Market1, Market2)

This will handle all your data and will allow you to easily add markets in the future. The downside is that you have to ensure that you don't have multiple entries for the same data ie "Gold - Silver" and "Silver - Gold"

With this structure you can just ask the Table for the Results at "Gold" and "Silver".

However producing a tabular result of all markets will be a bit more complex and I'd leave that for another SO question :D

Peter M