Hi,

I have a form with a ComboBox, two labels named "Price" and 'Dealer Cost" respectively a NumericUpDown control
and two buttons named "calculate Commission" and "Enter Another product" respectively.
I want to be able to retrieve the corresponding Price and Dealer Cost from the local database and display them next to the labels
when a product is selected from the ComboBox.

Also when i click on the "Enter Another product" button i get the following error:
"system.formatexception input string was not in a correct format"
Below is a snippet of code for the form

Sub GetPrice()
        'create a new database connection
        Dim ssceconn As New System.Data.SqlServerCe.SqlCeConnection("Data Source = C:\users\Adrian\My Documents\OPS.sdf")

        'Open the database connection
        ssceconn.Open()

        'Create an instance of SqlCeCommand
        Dim cmd As System.Data.SqlServerCe.SqlCeCommand

        'Create an instance of SqlCeDataReader
        Dim dtr As System.Data.SqlServerCe.SqlCeDataReader

        'Retrieve data from the Product table
        cmd = New System.Data.SqlServerCe.SqlCeCommand("SELECT price, dealer_cost FROM Product " &
              "WHERE (p_desc LIKE '" & cboProduct.Text & "')", ssceconn)
        dtr = cmd.ExecuteReader()

        'Read and display the data
        While dtr.Read()
            lblProductPrice.Text = dtr("price")
            lblDealerCost.Text = dtr("dealer_cost")
        End While
        'Close the DataReader
        dtr.Close()

        'Close the database connection
        ssceconn.Close()

    End Sub

    Private Sub cmdEnterAnother_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnterAnother.Click
        'Assign values to the arrays
        Product(I) = cboProduct.SelectedItem
        
       [B]'This line of code produces a System.FormatException error- input string not in correct format
        Price(I) = Convert.ToDecimal(lblProductPrice.Text)[/B]
        Cost(I) = lblDealerCost.Text
        Quantity(I) = nudQuantity.Text

        'Increment the index by 1
        I = I + 1

        'Call the ClearFields function
        ClearFields()

    End Sub

Thanks for your help.

Hi,

I have a form with a ComboBox, two labels named "Price" and 'Dealer Cost" respectively a NumericUpDown control
and two buttons named "calculate Commission" and "Enter Another product" respectively.
I want to be able  to retrieve the corresponding Price and Dealer Cost from the local database and display them next to the labels
when a product is selected from the ComboBox.

Also when i click on the "Enter Another product" button i get the following error:
"system.formatexception input string was not in a correct format"
Below is a snippet of code for the form
Sub GetPrice()
        'create a new database connection
        Dim ssceconn As New System.Data.SqlServerCe.SqlCeConnection("Data Source = C:\users\Adrian\My Documents\OPS.sdf")

        'Open the database connection
        ssceconn.Open()

        'Create an instance of SqlCeCommand
        Dim cmd As System.Data.SqlServerCe.SqlCeCommand

        'Create an instance of SqlCeDataReader
        Dim dtr As System.Data.SqlServerCe.SqlCeDataReader

        'Retrieve data from the Product table
        cmd = New System.Data.SqlServerCe.SqlCeCommand("SELECT price, dealer_cost FROM Product " &
              "WHERE (p_desc LIKE '" & cboProduct.Text & "')", ssceconn)
        dtr = cmd.ExecuteReader()

        'Read and display the data
        While dtr.Read()
            lblProductPrice.Text = dtr("price")
            lblDealerCost.Text = dtr("dealer_cost")
        End While
        'Close the DataReader
        dtr.Close()

        'Close the database connection
        ssceconn.Close()

    End Sub

    Private Sub cmdEnterAnother_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnterAnother.Click
        'Assign values to the arrays
        Product(I) = cboProduct.SelectedItem
        
       'This line of code produces a System.FormatException error- input string not in correct format
        Price(I) = Convert.ToDecimal(lblProductPrice.Text)
        Cost(I) = lblDealerCost.Text
        Quantity(I) = nudQuantity.Text

        'Increment the index by 1
        I = I + 1

        'Call the ClearFields function
        ClearFields()

    End Sub
This article has been dead for over six months. Start a new discussion instead.