Click here to Skip to main content
15,915,508 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,
here is my code.
With DGVMargin
            For i As Integer = 0 To .Rows.Count - 1
                If txttype.Text = "NORMAL" Then
                    If txtDiscount.Text = .Rows(i).Cells("DiscountNormal").Value Then
                        decodeDiscount()
                        Updatefunction()
                        Exit For
                    Else
                        decodeDiscount()
                        Insert()
                        Exit For
                    End If
  Next
        End With

Now i want to update the txtDiscount value if it is already exist,else it will go to insert a new data.
Now the problem is it will not going to update the value even already have the same txtDiscount value. The system will always go to the Insert() function. It will not go Updatefunction to update the value.
Is there any problem or mistake in my code?
Your help is appreciated. Thanks.
Posted
Updated 18-Jan-13 15:45pm
v3

1 solution

If it is always go to the Insert() function that's mean
VB
If txtDiscount.Text = .Rows(i).Cells("DiscountNormal").Value Then

above conditions is false for all time. My suggestion is add the breakpoints to that line and verify the value of txtDiscount.Text and Rows(i).Cells("DiscountNormal").Value separately. then you can get the idea whats wrong here.

It seems this is Casting issue.
Convert
Rows(i).Cells("DiscountNormal").Value.ToString()
and check.
or
CAST both txtDiscount.Text and
Rows(i).Cells("DiscountNormal").Value
to discount type (integer/decimal) and check
 
Share this answer
 
v4
Comments
Des DC 18-Jan-13 22:44pm    
Hi,Tharaka MTR.
Yes.I add breakpoints there and checked the value.
the value is correct,but don't know why it will not compare with the current data to check the value.
Tharaka MTR 18-Jan-13 23:13pm    
Could you please convert the Row value to string CAST both txtDiscount.Text and Rows(i).Cells("DiscountNormal").Value to discount type (integer/decimal) and check
Des DC 18-Jan-13 23:48pm    
Tharaka MTR,i tried your way.
Rows(i).Cells("DiscountNormal").Value.ToString() is not work.
Sorry i have to ask a question about second way,is the second cast like this?
CDec(txtDiscount.Text)=CDec(Rows(i).Cells("DiscountNormal").Value)?
Tharaka MTR 19-Jan-13 0:25am    
when you using Rows(i).Cells("DiscountNormal").Value.ToString(), what is the error you got?

you can using Convert.ToDecimal()
http://msdn.microsoft.com/en-us/library/hf9z3s65(v=vs.90).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2
Des DC 19-Jan-13 1:06am    
When I'm using Rows(i).Cells("DiscountNormal").Value.ToString() there is no error. Just the output is not as expected.
But I tried it again and again with my code just now. It sometimes can update the value but sometimes cant. I'm trying to find out the what's the problem. Anyway thanks for your reply. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900