Hi. My problem is, the data that I pull from the database, when try to multiply it, it didn't multiply.

The database has Fruit and FruitPrice column. When select fruit form the combo box, it will search the price. But I can't seem to multiply it. The price is display at PriceTextBox but when multiply it, it shows 0 in the TotalTextBox. It is a simple problem but I've tried everything I know but it still didn't multiply.

This is my search coding:

con.ConnectionString = "PROVIDER=Microsoft.Jet.Oledb.4.0; Data source =C:\Documents and Settings\~LaiLi~\My Documents\Visual Studio 2005\Projects\MoreWever\MoreWever\bin\Debug\Inventory.mdb"
        sql = "SELECT * FROM Sales WHERE Fruit = '" & FruitComboBox.Text & "'"
        con.Open()
        Dim cmd As OleDbCommand
        Dim dr As OleDbDataReader
        Dim FruitDecimal, TotalPrice, FruitPrice As Decimal
        Dim QuanNum As Integer

        cmd = New OleDbCommand(sql, con)
        dr = cmd.ExecuteReader

        While dr.Read()
            FruitDecimal = dr("FruitPrice")
            FruitPrice = FruitDecimal
        End While

        TotalPrice = FruitPrice * QuanNum
        QuanNum = Integer.Parse(QuantityTextBox.Text)
        PriceTextBox.Text = FruitPrice.ToString()
        TotalTextBox.Text = TotalPrice.ToString()
        con.Close()

Hope someone has any idea about it.

Member Avatar for Unhnd_Exception

Your multiplying FuitPrice by QuanNum and your never assigning a value to QuanNum. Your multiplying by 0 everytime.

commented: nice catch. +8
con.ConnectionString = "PROVIDER=Microsoft.Jet.Oledb.4.0; Data source =C:\Documents and Settings\~LaiLi~\My Documents\Visual Studio 2005\Projects\MoreWever\MoreWever\bin\Debug\Inventory.mdb"
        sql = "SELECT * FROM Sales WHERE Fruit = '" & FruitComboBox.Text & "'"
        con.Open()
        Dim cmd As OleDbCommand
        Dim dr As OleDbDataReader
        Dim FruitDecimal, TotalPrice, FruitPrice As Decimal
        Dim QuanNum As Integer

        cmd = New OleDbCommand(sql, con)
        dr = cmd.ExecuteReader

        While dr.Read()
            FruitDecimal = dr("FruitPrice")
            FruitPrice = FruitDecimal
        End While
        QuanNum = Integer.Parse(QuantityTextBox.Text)
        TotalPrice = FruitPrice * QuanNum
        PriceTextBox.Text = FruitPrice.ToString()
        TotalTextBox.Text = TotalPrice.ToString()
        con.Close()

Try this code, now it will not show 0 value.

Ah~ so silly of me. I didn't know it will effect much if the order isn't right. I will be more careful next time. Thank you for correcting that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.