2 Replies - 1656 Views - Last Post: 11 November 2011 - 01:27 PM Rate Topic: -----

#1 ChrisTech  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-November 11

Error when adding item to a listview

Posted 10 November 2011 - 02:44 AM

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?

Attached image(s)

  • Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: Error when adding item to a listview

#2 DimitriV  Icon User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: Error when adding item to a listview

Posted 10 November 2011 - 02:58 AM

In the .Item area, I believe that you use a 0-based Integer value instead of a string.
Was This Post Helpful? 0
  • +
  • -

#3 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 386
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Error when adding item to a listview

Posted 11 November 2011 - 01:27 PM

for your error, MSDN says


No column with the specified name was found.

Maybe is "item" and not "Item". Also you can use GetString(<columnIndex>)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1