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")

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

            '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  _

            End While

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

        'Close database connection
    End Sub

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

Attachments Sales_Screen_Error_Listview.jpg 47.3 KB

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.

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