473,325 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

addition problem

I am having a problem updating the main table (2nd set of
code) based on the total of all details entered (1st set
of code). It seems to be off by less than a dollar. I
thought it was a decimal issue but all my ctypes are set
to decimal. I am resetting all my textfields to "" after
adding the detail information. Any help would be
appreciated.

Here's the code:

'this updates the details table with the amounts

Dim lastid As Integer

SqlSelectCommand12.Parameters("@userid").Value =
CType(lbluserid.Text, Integer)

SqlDataAdapter12.Fill(Dsmaxtrxid1)

lblmaxtrxid.DataBind()

lastid = CType(lblmaxtrxid.Text, Integer)

'set details information and save

txtItem1.Visible = True

txtqty1.Visible = True

txtunit1.Visible = True

Dim qty1 As Decimal

Dim unit1 As Decimal

qty1 = CType(txtqty1.Text, Decimal)

unit1 = CType(txtunit1.Text, Decimal)

lbleucost.Text = qty1 * unit1

Dim EUC As Decimal

EUC = CType(lbleucost.Text, Decimal)

If txtEC.Text = "" Then

txtEC.Text = lbleucost.Text

Else

Dim ectext As Decimal

ectext = CType(txtEC.Text, Decimal)

txtEC.Text = ectext + EUC

End If

Dim ec As Decimal

ec = CType(lbleucost.Text, Decimal)

SqlUpdateCommand2.Parameters("@trxid").Value =
lastid

SqlUpdateCommand2.Parameters("@desc").Value =
txtItem1.Text

SqlUpdateCommand2.Parameters("@qty").Value = qty1

SqlUpdateCommand2.Parameters("@uc").Value = unit1

SqlUpdateCommand2.Parameters("@ec").Value = ec

SqlConnection1.Open()

SqlUpdateCommand2.ExecuteNonQuery()

SqlConnection1.Close()



txtEC.Visible = True

ShowFields()

txtItem1.Text = ""

txtqty1.Text = ""

txtunit1.Text = ""

lbleucost.Text = ""

txtItem1.TabIndex = 1

txtqty1.TabIndex = 2

txtunit1.TabIndex = 3

Button1.TabIndex = 4

resetTabs()

BindDetails()



' Updates the main table with the total estimated charges

Dim inttrx As Integer

inttrx = CType(lblmaxtrxid.Text, Integer)

SqlUpdateCommand5.Parameters("@ec").Value =
txtEC.Text

SqlUpdateCommand5.Parameters("@tid").Value =
inttrx

SqlConnection1.Open()

SqlUpdateCommand5.ExecuteNonQuery()

SqlConnection1.Close()

Jul 21 '05 #1
2 1209
I forgot to mention earlier...

This is what specifically is occurring.
First entry goes in fine.
The next entry if it is a whole goes in fine and adds
properly.
Anytime you put another entry in that has cents it adds
the whole number but not the cents.

-----Original Message-----
I am having a problem updating the main table (2nd set ofcode) based on the total of all details entered (1st set
of code). It seems to be off by less than a dollar. I
thought it was a decimal issue but all my ctypes are set
to decimal. I am resetting all my textfields to "" afteradding the detail information. Any help would be
appreciated.

Here's the code:

'this updates the details table with the amounts

Dim lastid As Integer

SqlSelectCommand12.Parameters("@userid").Value =
CType(lbluserid.Text, Integer)

SqlDataAdapter12.Fill(Dsmaxtrxid1)

lblmaxtrxid.DataBind()

lastid = CType(lblmaxtrxid.Text, Integer)

'set details information and save

txtItem1.Visible = True

txtqty1.Visible = True

txtunit1.Visible = True

Dim qty1 As Decimal

Dim unit1 As Decimal

qty1 = CType(txtqty1.Text, Decimal)

unit1 = CType(txtunit1.Text, Decimal)

lbleucost.Text = qty1 * unit1

Dim EUC As Decimal

EUC = CType(lbleucost.Text, Decimal)

If txtEC.Text = "" Then

txtEC.Text = lbleucost.Text

Else

Dim ectext As Decimal

ectext = CType(txtEC.Text, Decimal)

txtEC.Text = ectext + EUC

End If

Dim ec As Decimal

ec = CType(lbleucost.Text, Decimal)

SqlUpdateCommand2.Parameters("@trxid").Value =
lastid

SqlUpdateCommand2.Parameters("@desc").Value =
txtItem1.Text

SqlUpdateCommand2.Parameters("@qty").Value = qty1

SqlUpdateCommand2.Parameters("@uc").Value = unit1

SqlUpdateCommand2.Parameters("@ec").Value = ec

SqlConnection1.Open()

SqlUpdateCommand2.ExecuteNonQuery()

SqlConnection1.Close()



txtEC.Visible = True

ShowFields()

txtItem1.Text = ""

txtqty1.Text = ""

txtunit1.Text = ""

lbleucost.Text = ""

txtItem1.TabIndex = 1

txtqty1.TabIndex = 2

txtunit1.TabIndex = 3

Button1.TabIndex = 4

resetTabs()

BindDetails()



' Updates the main table with the total estimated charges

Dim inttrx As Integer

inttrx = CType(lblmaxtrxid.Text, Integer)

SqlUpdateCommand5.Parameters("@ec").Value =
txtEC.Text

SqlUpdateCommand5.Parameters("@tid").Value =
inttrx

SqlConnection1.Open()

SqlUpdateCommand5.ExecuteNonQuery()

SqlConnection1.Close()

.

Jul 21 '05 #2
Hi Derek,

Thanks for posting.

I have reviewed the code. Do you mean that the txtEC.Text will lose its
decimal fraction or the corresponding value in the SQL Server database will
lose its decimal fraction after updaing?

If txtEC.Text is losing the decimal fraction, maybe we can set some break
points in the method and track the variables. In addition, we may also try
to simplify the code to isolate the problem here. For example, I simplify
the code to the following:

Dim qty1 As Decimal
Dim unit1 As Decimal

qty1 = CType(txtqty1.Text, Decimal)
unit1 = CType(txtunit1.Text, Decimal)
lbleucost.Text = qty1 * unit1

Dim EUC As Decimal
EUC = CType(lbleucost.Text, Decimal)

If txtEC.Text = "" Then
txtec.Text = lbleucost.Text
Else
Dim ectext As Decimal
ectext = CType(txtEC.Text, Decimal)
txtEC.Text = ectext + EUC
End If

txtQty1.Text = ""
txtUnit1.Text = ""
lbleucost.Text = ""

There seems to be no problem with this simplified code on my side. I am
using VS.Net 2003. However, I am not very sure why we need to use the label
"lbleucost" here. It does not seem to display anything.

If there is no problem with txtEC.Text and the value in the database loses
its decimal fraction, may be the problem here is with the update command or
on the database side.

I hope this makes sense to you.

Regards,

Felix Wang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #3

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

Similar topics

24
by: Alex Vinokur | last post by:
Consider the following statement: n+i, where i = 1 or 0. Is there more fast method for computing n+i than direct computing that sum? -- Alex Vinokur email: alex DOT vinokur AT gmail DOT...
34
by: Andy | last post by:
Hi, Are 1 through 4 defined behaviors in C? unsigned short i; unsigned long li; /* 32-bit wide */ 1. i = 65535 + 3; 2. i = 1 - 3; 3. li = (unsigned long)0xFFFFFFFF + 3; 4. li = 1...
23
by: Alex Vinokur | last post by:
Consider the following statement: n+i, where i = 1 or 0. Is there more fast method for computing n+i than direct computing that sum? -- Alex Vinokur email: alex DOT vinokur AT gmail DOT...
3
by: snow.carriers | last post by:
Let me first state that I'm using Borland Turbo C++, it's relatively old so the new string methods won't work. Anyways, first I'm trying to collect a line of a string (with numbers, letters,...
0
by: edurazee | last post by:
I am able to create BoundFields and Footer-rows dynamically like this in my GridView: protected void Page_Load(object sender, EventArgs e) { CreateGridView(); ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.