473,472 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ARGH! Converting the value of a dtatable from a string to a Double

Hi All :-)

I found the way to get my column sum (Thanks Cor I did it a little different, but the result is what I wanted) I used:

dt_stat_report_3b.Columns.Add(New DataColumn("Sum", GetType(Double), "sum(Column_10_ld_act_125_gtr_fy_fy_hh_avg)"))
where dt_stat_report_3b is my datatable, Sum is my column name and sum(Column_10_ld_act_125_gtr_fy_fy_hh_avg) is the sum of the column I needed. This Does return me the correct value in the column I've specified, but now I need that value to be stored in a variable that I can use in another calculation. I've tried:

ld_act_125_gtr_fy_hh_avg_grnd_tot = CDbl(dt_stat_report_3b.Columns.Item(15).ToString)

Where ld_act_125_gtr_fy_hh_avg_grnd_tot is the variable and is declared as a Double. This returns an error that the input string was not in the correct format. What I really want to do is get the value from that column and populate the variable with it. I CAN'T get the CDbl() to work! I've tried to do it as CDbl(), I tried System.Convert.ToDouble() but I ALWAYS get an error that the input string was in an incorrect format. I just want the VALUE from the Column that I've summed! Please, can someone explain how to get the string to convert to a double or how to get dt_stat_report_3b.Columns.Item(15).Value? Value is not an option and I don't know what else to try!

Any help is GREATLY Appreciated, since I have spent all day on this problem!

Thanks!

Coleen

Nov 21 '05 #1
9 2054
jim
Hi Coleen,

i'm not 100% sure that i understand your problem. are you able to get the
value from the computed field? if so, what datatype is the column in which
the data resides.

if you just need to convert the string to a double then you can use the
parse method.

Double.Parse(dt_stat_report_3b.Columns.Item(15).To String)

overloaded methods allow you to provide a formatprovider and/or a
numberstyle

if the computed column was created with a datatype of Double, then
theoretically

CDbl(myDatatable.Rows(myRowIndex)(myComputedColumn Name))

should pull the data from the field... (theoretically...) but, i haven't
worked much with computed columns yet.

hope this helps.

good luck,

jim
"Coleen" <co**********@yaho.com> wrote in message
news:e4**************@TK2MSFTNGP12.phx.gbl...
Hi All :-)

I found the way to get my column sum (Thanks Cor I did it a little
different, but the result is what I wanted) I used:

dt_stat_report_3b.Columns.Add(New DataColumn("Sum", GetType(Double),
"sum(Column_10_ld_act_125_gtr_fy_fy_hh_avg)"))
where dt_stat_report_3b is my datatable, Sum is my column name and
sum(Column_10_ld_act_125_gtr_fy_fy_hh_avg) is the sum of the column I
needed. This Does return me the correct value in the column I've specified,
but now I need that value to be stored in a variable that I can use in
another calculation. I've tried:

ld_act_125_gtr_fy_hh_avg_grnd_tot =
CDbl(dt_stat_report_3b.Columns.Item(15).ToString)

Where ld_act_125_gtr_fy_hh_avg_grnd_tot is the variable and is declared as a
Double. This returns an error that the input string was not in the correct
format. What I really want to do is get the value from that column and
populate the variable with it. I CAN'T get the CDbl() to work! I've tried
to do it as CDbl(), I tried System.Convert.ToDouble() but I ALWAYS get an
error that the input string was in an incorrect format. I just want the
VALUE from the Column that I've summed! Please, can someone explain how to
get the string to convert to a double or how to get
dt_stat_report_3b.Columns.Item(15).Value? Value is not an option and I
don't know what else to try!

Any help is GREATLY Appreciated, since I have spent all day on this problem!

Thanks!

Coleen
Nov 21 '05 #2
Coleen,
ld_act_125_gtr_fy_hh_avg_grnd_tot = CDbl
(dt_stat_report_3b.Columns.Item(15).ToString)


The datatable is created vertical (columns) and used horizontal (rows).

Is this what you mean?

ld_act_125_gtr_fy_hh_avg_grnd_tot = dt_stat_report_3b.rows("Sum").Item(15)

I hope this helps?

Cor
Nov 21 '05 #3
I've tried both suggestions. Here is the code I'm trying:

dt_stat_report_3b.Columns.Add(New DataColumn("Sum", GetType(Double), "sum(Column_10_ld_act_125_gtr_fy_fy_hh_avg)"))
where dt_stat_report_3b. is the datatable, Sum is the compute, and Column_10_ld_act_125_gtr_fy_fy_hh_avg is the column that I'm getting the grand total for.

I have a For/Next Loop where I have variable ld_pct_125_tot_gtr_fy_hh that I need to have the following calculation:

ld_pct_125_tot_gtr_fy_hh = ld_act_125_gtr_fy_hh_avg/sum for 17 rows in the Loop. Each row has a different average thus the variable ld_act_125_gtr_fy_hh_avg. the computed column "sum" is the total of all the rows of the variable ld_act_125_gtr_fy_hh_avg.

I've tried EVERYTHING I can think of to get the value from the computed column "sum" into a variable name. I either get a message that the input string was not in the correct format, or I get a message when I try:

ld_act_125_gtr_fy_hh_avg_grnd_tot = CDbl(dt_stat_report_3b.Rows(0).Item(0).ToString) that the Row or Item does not exist.

There HAS to be a way to get the value from the computed item into a variable as a double so that I can use that value in my next calculation. I' am at a loss and in desperate need of help! Thanks you so much for trying :-)

Coleen


"Cor Ligthert" <no**********@planet.nl> wrote in message news:uA**************@TK2MSFTNGP10.phx.gbl...
Coleen,
ld_act_125_gtr_fy_hh_avg_grnd_tot = CDbl
(dt_stat_report_3b.Columns.Item(15).ToString)


The datatable is created vertical (columns) and used horizontal (rows).

Is this what you mean?

ld_act_125_gtr_fy_hh_avg_grnd_tot = dt_stat_report_3b.rows("Sum").Item(15)

I hope this helps?

Cor

Nov 21 '05 #4
For anyone looking at this, here is the solution thanks to my very good VB.Net Teacher whom I called in desperation - Thanks Jerry!!!

Dim the variable as Public. On PreRender use:

PublicVariableName = DatatabelName.Row(0).Cell(15).Value

I could not get the option of value after row or cell in anything I tried within my For/Next Loop. I can now use this Variable value to do my calculations for the percentage rate. Again - THANKS Jerry!
"Coleen" <co**********@yaho.com> wrote in message news:Oa*************@tk2msftngp13.phx.gbl...
I've tried both suggestions. Here is the code I'm trying:

dt_stat_report_3b.Columns.Add(New DataColumn("Sum", GetType(Double), "sum(Column_10_ld_act_125_gtr_fy_fy_hh_avg)"))
where dt_stat_report_3b. is the datatable, Sum is the compute, and Column_10_ld_act_125_gtr_fy_fy_hh_avg is the column that I'm getting the grand total for.

I have a For/Next Loop where I have variable ld_pct_125_tot_gtr_fy_hh that I need to have the following calculation:

ld_pct_125_tot_gtr_fy_hh = ld_act_125_gtr_fy_hh_avg/sum for 17 rows in the Loop. Each row has a different average thus the variable ld_act_125_gtr_fy_hh_avg. the computed column "sum" is the total of all the rows of the variable ld_act_125_gtr_fy_hh_avg.

I've tried EVERYTHING I can think of to get the value from the computed column "sum" into a variable name. I either get a message that the input string was not in the correct format, or I get a message when I try:

ld_act_125_gtr_fy_hh_avg_grnd_tot = CDbl(dt_stat_report_3b.Rows(0).Item(0).ToString) that the Row or Item does not exist.

There HAS to be a way to get the value from the computed item into a variable as a double so that I can use that value in my next calculation. I' am at a loss and in desperate need of help! Thanks you so much for trying :-)

Coleen


"Cor Ligthert" <no**********@planet.nl> wrote in message news:uA**************@TK2MSFTNGP10.phx.gbl...
Coleen,
ld_act_125_gtr_fy_hh_avg_grnd_tot = CDbl
(dt_stat_report_3b.Columns.Item(15).ToString)


The datatable is created vertical (columns) and used horizontal (rows).

Is this what you mean?

ld_act_125_gtr_fy_hh_avg_grnd_tot = dt_stat_report_3b.rows("Sum").Item(15)

I hope this helps?

Cor

Nov 21 '05 #5
Well, I spoke to soon...this works great if you just want to display the value, but if you want to use the value to perform another calculation, I get "Infinity" in the cell where I'm trying to use the grand total I get from the PreRender.. any other suggestions?

PLEASE? TIA
"Coleen" <co**********@yaho.com> wrote in message news:OV*************@TK2MSFTNGP12.phx.gbl...
For anyone looking at this, here is the solution thanks to my very good VB.Net Teacher whom I called in desperation - Thanks Jerry!!!

Dim the variable as Public. On PreRender use:

PublicVariableName = DatatabelName.Row(0).Cell(15).Value

I could not get the option of value after row or cell in anything I tried within my For/Next Loop. I can now use this Variable value to do my calculations for the percentage rate. Again - THANKS Jerry!
"Coleen" <co**********@yaho.com> wrote in message news:Oa*************@tk2msftngp13.phx.gbl...
I've tried both suggestions. Here is the code I'm trying:

dt_stat_report_3b.Columns.Add(New DataColumn("Sum", GetType(Double), "sum(Column_10_ld_act_125_gtr_fy_fy_hh_avg)"))
where dt_stat_report_3b. is the datatable, Sum is the compute, and Column_10_ld_act_125_gtr_fy_fy_hh_avg is the column that I'm getting the grand total for.

I have a For/Next Loop where I have variable ld_pct_125_tot_gtr_fy_hh that I need to have the following calculation:

ld_pct_125_tot_gtr_fy_hh = ld_act_125_gtr_fy_hh_avg/sum for 17 rows in the Loop. Each row has a different average thus the variable ld_act_125_gtr_fy_hh_avg. the computed column "sum" is the total of all the rows of the variable ld_act_125_gtr_fy_hh_avg.

I've tried EVERYTHING I can think of to get the value from the computed column "sum" into a variable name. I either get a message that the input string was not in the correct format, or I get a message when I try:

ld_act_125_gtr_fy_hh_avg_grnd_tot = CDbl(dt_stat_report_3b.Rows(0).Item(0).ToString) that the Row or Item does not exist.

There HAS to be a way to get the value from the computed item into a variable as a double so that I can use that value in my next calculation. I' am at a loss and in desperate need of help! Thanks you so much for trying :-)

Coleen


"Cor Ligthert" <no**********@planet.nl> wrote in message news:uA**************@TK2MSFTNGP10.phx.gbl...
Coleen,
ld_act_125_gtr_fy_hh_avg_grnd_tot = CDbl
(dt_stat_report_3b.Columns.Item(15).ToString)


The datatable is created vertical (columns) and used horizontal (rows).

Is this what you mean?

ld_act_125_gtr_fy_hh_avg_grnd_tot = dt_stat_report_3b.rows("Sum").Item(15)

I hope this helps?

Cor

Nov 21 '05 #6

Coleen,

I am really confused by you, do you want a "compute" the sum of a vertical
column or an expression to get the sum of horizontal items in a rows?

Datatable.Compute
http://msdn.microsoft.com/library/de...mputetopic.asp

And what you are using in my opinion.
Datacolumn.Expression
http://msdn.microsoft.com/library/de...ssiontopic.asp

What is it you want?

Cor

Cor
Nov 21 '05 #7
Thanks Cor :-)

I want to get the grand total (sum) of one column (not row) Then I need to take that grand total and divide each row of the column by the grand total in order to get percentage rate. This is done In MS Excel as:

Column A Column B

row 1 100 =100/600 (Column A Row 1/Column A Total)

row 2 200 =200/600 (Column A Row 1/Column A Total)

row 3 300 =300/600 (Column A Row 1/Column A Total)

Total 600

I need to get the value of "600" into a variable that I can use to divide each row for column A by. Does that Make a little more sense? I ended up creating two datagrids. One that does all the calculations up to the grand total that I need (column A) and I created a variable to store the total for Column A "600" in after I did the databind on the first datagrid. In the second datagrid I took the grand total from Column A "600" and used it in my second datagrid to divide the values from each row in Column A with. Since each row in column A has a variable associated with it (I know there will always be 17 rows of data) I created 17 separate variables for each row in datagrid 1 and use those variables divided by the grand total (Total Column A - "600") from datagrid 1 as available in datagrid 2. Now I hide both datagrids and populate an html table with the values from datagrid1 and datagrid 2 to display to the user. Not simple, not pretty, but it works.

If there is an easier way to get percentage rates from a calculated value for each row, I'd love to know about it...

Thanks - I hope you understand what I was trying to do. This type of calculation is EXTREMELY easy in Excel, but when you have to do all the work that Excel does for you automatically, it is VERY difficult.

Coleen

"Cor Ligthert" <no**********@planet.nl> wrote in message news:e1*************@TK2MSFTNGP11.phx.gbl...

Coleen,

I am really confused by you, do you want a "compute" the sum of a vertical
column or an expression to get the sum of horizontal items in a rows?

Datatable.Compute
http://msdn.microsoft.com/library/de...mputetopic.asp

And what you are using in my opinion.
Datacolumn.Expression
http://msdn.microsoft.com/library/de...ssiontopic.asp

What is it you want?

Cor



Cor

Nov 21 '05 #8
On 2004-08-14, Coleen <co**********@yaho.com> wrote:
This is a multi-part message in MIME format.

------=_NextPart_000_0008_01C48157.E7166940
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Thanks Cor :-)

I want to get the grand total (sum) of one column (not row) Then I need =
to take that grand total and divide each row of the column by the grand =
total in order to get percentage rate. This is done In MS Excel as:

Column A Column B

row 1 100 =3D100/600 (Column A Row 1/Column A Total)

row 2 200 =3D200/600 (Column A Row 1/Column A Total)

row 3 300 =3D300/600 (Column A Row 1/Column A Total)

Total 600=20

I need to get the value of "600" into a variable that I can use to =
divide each row for column A by. Does that Make a little more sense? I =
ended up creating two datagrids.


DataTable1.Columns.Add("ColumnAPercentage", _
GetType(Decimal), _
"ColumnA/SUM(ColumnA)")

Is that what you're after? This would give you a new column of:

16%
33%
50%

(assuming you format as percentages).

Nov 21 '05 #9
Coleen,

Can you try this extremely easy sample, a new project a datagrid and than
run.

I (think) hope this helps?

Cor

\\\
Private Sub Form1_Load(ByVal sender As _
Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim dt As New DataTable("Coleen")
dt.Columns.Add("Fig", GetType(System.Int32))
dt.Columns.Add("Perc", GetType(System.Int32))
For i As Integer = 0 To 5
Dim dr As DataRow = dt.NewRow
dr(0) = i + 1
dt.Rows.Add(dr)
Next
Dim dr2 As DataRow = dt.NewRow
Dim sum As Integer = _
CInt(dt.Compute("Sum(Fig)", ""))
dr2(0) = sum
dt.Rows.Add(dr2)
dt.Columns(1).Expression = _
"Fig * 100/ " & sum.ToString
DataGrid1.DataSource = dt
End Sub
///
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: The Plankmeister | last post by:
Hi... I'm trying my hardest to understand fully how sessions work and how best to use them. However, all I can find is information that doesn't tell me anything other than that sessions store...
2
by: Wired Earp | last post by:
I don't get it. First of all, it claims to run on a JRE. This is obviously a fraud, it even says so when you attempt to start it: "The JAVA_HOME variable should point to a JDK and not a JRE". I can...
3
by: The Plankmeister | last post by:
Hi... I'm attempting to keep everything I write compliant with xhtml 1.0 strict. And It's very bizarre. Why on earth won't this validate: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html...
1
by: Jim Moe | last post by:
Hello, I am (slowly) in the process of changing a table-based layout to CSS/div-based. One area that uses tables a lot is the main nav menu. I have discovered that tables have advantage: all...
1
by: Henry Rollins | last post by:
This is driving me nuts. I have created a Class Assembly in .NET C# which is to be used by traditional ASP pages. I registered it just fine with the regASM command and it work - about 2/3 of...
1
by: Cliff Williams | last post by:
How are people managing multiple, interdependent projects in the same solution? If I have to rebuild my solution file one more time, I think my head is going to spin around and pop off. I've...
0
by: Toby Mathews | last post by:
Hi there, I have a problem with a C# AP.NET app. running on my local machine, Sporadically (but more and more frequently) I get the above error message when code running on my laptop trys to...
1
by: RWC | last post by:
Hi Folks, I have a windows 2000 server installation, IIS is running and the ASP.NET 1.1 SDK has been installed. I'm reading a book on ASP.NET and the lessons call for the first line to read <%@...
2
by: SorceCode | last post by:
Hey guys, good old > Debug Assertion Failed! > File: dbgdel.cpp > Line: 47 > Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) Rears its ugly head agian! Ok heres what Im up to..
6
by: darrel | last post by:
I'm using some validators for a form. I'm noticing that it writes the text out to the browser as a SPAN with it's visibility set to none. The problem is that it still takes up space, so I have...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.