By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,569 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

addition problem

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.