I am developing a point of sale program for a project subject. The trouble im having is when i press on the button to add the item from a textbox to a listview i receive an error: See attached Screenshot.

my code is:

Private Sub SalesScreen_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.CustomerTextBox.Text = "Cash Customer"

        'Sets the properties of the listview
        SalesScreenListView.View = View.Details
        SalesScreenListView.GridLines = True
        SalesScreenListView.FullRowSelect = True

        'Add 4 columns and column names
        SalesScreenListView.Columns.Add("Item", 100)
        SalesScreenListView.Columns.Add("Description", 430)
        SalesScreenListView.Columns.Add("Quantity", 70)
        SalesScreenListView.Columns.Add("Price", 70)

        'Set all Textbox properties to default
        Me.SubTotalTextBox.Text = Format("0.00", "currency")
        Me.TaxTextBox.Text = Format("0.00", "currency")
        Me.TotalTextBox.Text = Format("0.00", "currency")
        Dim InvoiceNum As String
        InvoiceNum = IncrementInvoice(InvoiceNumberTextBox.Text)
        Me.InvoiceNumberTextBox.Text = InvoiceNum
    End Sub

Private Sub ProductCodeButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ProductCodeButton.Click
        Dim connection As New SqlClient.SqlConnection
        connection.ConnectionString = ("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True")
        connection.Open()

        Dim adaptor As New SqlClient.SqlDataAdapter
        Dim dataset As New DataSet

        Try
            
            'Search for data in the SQL database using an SQL Select statement.
            Dim command As New SqlClient.SqlCommand("SELECT * FROM [Products] WHERE ProductID= '" & ProductCodeTextBox.Text & "'OR Description='" & ProductCodeTextBox.Text & "';", connection)
            Dim dr As SqlClient.SqlDataReader = command.ExecuteReader(CommandBehavior.Default)
            'Add rows to the listview for every match found in the database
            While dr.Read()
                Dim new_item As New  _
                ListViewItem(dr.Item("Item").ToString)
                new_item.SubItems.Add(dr.Item("Description").ToString)
                new_item.SubItems.Add(dr.Item("Quantity").ToString)
                new_item.SubItems.Add(dr.Item("Price").ToString)
                SalesScreenListView.Items.Add(new_item)


            End While
            dr.Close()

        Catch ex As Exception
            MsgBox(ex.ToString)  'Show error when something goes wrong
        End Try

        'Close database connection
        connection.Close()
    End Sub

Any help on what causes this error and how to correct it?

It may be line 82 in your code but we don't know what line in your POSTED code is throwing the error. Please identify the line where it dies.

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.