Solved

500pts: Extracting data from a table object?

Posted on 2006-07-20
9
200 Views
Last Modified: 2010-04-16
Hi..

Can anyone help, I seem to be having a problem getting data from a table.. I have a table and if i do

? myData.Table.Rows.Count

I get 1, so data is there...

I have tried various things like

I tried myData.Table.Columns["TOTAL"]

but there is no property VALUE for example...

Can anyone suggest what i am doing wrong?

Thanks in advance

Ian


0
Comment
Question by:ianinspain
9 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17145524
Hi ianinspain,

what object is myData : DataTable, DataTableCollection?

Apresto
0
 
LVL 29

Assisted Solution

by:Gautham Janardhan
Gautham Janardhan earned 250 total points
ID: 17145545
assuming that you are using datatable collection

the problem is that by stating Datatable.Table.columns[0]
u get the first column element

what u got to do is
myData.Table.Rows[i]["TOTAL"]
i is the row index i.e first row would be
myData.Table.Rows[0]["TOTAL"]
0
 

Author Comment

by:ianinspain
ID: 17145800
Thanks gauthampj,

That sort of works.. I get this

? myData.Table.Rows[0]["BO"]
{130.1}
    System.ValueType: {System.Double}
    Epsilon: 4.94065645841247E-324
    m_value: 130.1
    MaxValue: 1.7976931348623157E+308
    MinValue: -1.7976931348623157E+308
    NaN: NaN
    NegativeInfinity: -Infinity
    PositiveInfinity: +Infinity

But i really need just the value, i did try ToString but that didn't give the details either...

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:BBK_
ID: 17146127
myData.Table.Rows[0][0].ToString(), this should give you the first value in the first column
If it has value then , I think there may not be any column named "TOTAL"
0
 

Author Comment

by:ianinspain
ID: 17146237
No it works... but doing ToString doesn't give me the value..

0
 
LVL 3

Expert Comment

by:BBK_
ID: 17146253
U mean myData.Table.Rows[0][0] has value, but
myData.Table.Rows[0][0].ToString() throws error, rite?
0
 
LVL 3

Accepted Solution

by:
BBK_ earned 250 total points
ID: 17146321
Just a sample code


DataTable d = new DataTable();
d.Columns.Add("Test", typeof(System.String));
DataRow r = d.NewRow();
r[0] = "TESTCOLUMN";
d.Rows.Add(r);

MessageBox.Show(d.Rows[0][0].ToString());
0
 

Author Comment

by:ianinspain
ID: 17146927
Thanks BBK, yes i did try this... here is what i get.... If the column is a string then no probs....  But my column is a Double

? response.Data.Tables[0].Rows[0][1]
{0.0}
    System.ValueType: {System.Double}
    Epsilon: 4.94065645841247E-324
    m_value: 0.0
    MaxValue: 1.7976931348623157E+308
    MinValue: -1.7976931348623157E+308
    NaN: NaN
    NegativeInfinity: -Infinity
    PositiveInfinity: +Infinity
? response.Data.Tables[0].Rows[0][1].ToString
<overloaded>
    ToString: ((System.Double)((response.Data.Tables[0].Rows[0].get_Item(1)))).ToString+0 // method+offset
    ToString: ((System.Double)((response.Data.Tables[0].Rows[0].get_Item(1)))).ToString+0 // method+offset
    ToString: ((System.Double)((response.Data.Tables[0].Rows[0].get_Item(1)))).ToString+0 // method+offset
    ToString: ((System.Double)((response.Data.Tables[0].Rows[0].get_Item(1)))).ToString+0 // method+offset
0
 

Author Comment

by:ianinspain
ID: 17146986
ahh .. thnaks.. I got it

Double.Parse( response.Data.Tables[0].Rows[0][1].ToString())

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question