0

Hi all,
Check this code and please tell me a solution.I have 2 buttons (Pizza & pepsi),the price should display in textbox8 when i click on button, here the price had shown in Textbox8,but it is not getting added with next price when i click second button.

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        con.ConnectionString = str
        TextBox8.Text = 0.0
        adp = New SqlDataAdapter("select Item,Price from Bill where Id = '1'", con)
        adp.Fill(ds)
        DataGridView1.DataSource = ds.Tables(0)
        TextBox8.Text = ds.Tables(0).Rows(0)("Price") + TextBox8.Text -->
    End Sub
3
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by lolafuertes
0

If each time you call this button, you set the text value to 0, the old value is lost.

I would suggest to remove the line

TextBox8.Text = 0.0

from there and move it in an outer initializer sub.

Hope this helps

0

Thanks lolafuertes,
the value is not getting added with last one,instead it is showing like
(in textbox8) 75.00 75.00 75.00

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        con.ConnectionString = str
        adp = New SqlDataAdapter("select Count,Item,Price from Bill where Id = '1'", con)
        adp.Fill(ds)
        DataGridView1.DataSource = ds.Tables(0)
        TextBox8.Text = Convert.ToString(ds.Tables(0).Rows(0)("Price")) + TextBox8.Text
    End Sub

Edited by prathapsv3: n/a

0

Because TextBox8.Text is just a string you should convert to some kind of numeric (like double) to add it to another value like:

TextBox8.Text = String.Format("{0:C2}",CCur(ds.Tables(0).Rows(0)("Price")) + CCur(TextBox8.Text))

This will format the result as a currency, with 2 decimals. Each operand will be converted to currency before being added together.

Hope this helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.