0

I'm trying to load an access database table into a listview's columns. I 've managed to load the first 4 columns of the database but there is a problem with the 5th one.

Public Sub DisplayPasswords() Passes.Items.Clear() Dim dt As New DataTable Dim ds As New DataSet ds.Tables.Add(dt) Dim da As New OleDbDataAdapter("Select * from passwords", con) da.Fill(dt) Dim myRow As DataRow For Each myRow In dt.Rows Passes.Items.Add(myRow.Item(1)) Passes.Items(Passes.Items.Count - 1).SubItems.Add(myRow.Item(2)) Passes.Items(Passes.Items.Count - 1).SubItems.Add(myRow.Item(3)) Passes.Items(Passes.Items.Count - 1).SubItems.Add(myRow.Item(4)) Passes.Items(Passes.Items.Count - 1).SubItems.Add(myRow.Item(5)) Next End Sub 

The error:

Overload resolution failed because no Public 'Add' can be called with these arguments: 'Public Function Add(item As System.Windows.Forms.ListViewItem.ListViewSubItem) As System.Windows.Forms.ListViewItem.ListViewSubItem': 

This is an image of the error I get: https://i.sstatic.net/fHx1S.png

This is an image of my access database: https://i.sstatic.net/2tuZl.png

This is an image of my listview: https://i.sstatic.net/aVR7y.png

5
  • 1
    Well, index probably goes from 0 to 4 , not from 1 to 5 ... Commented Dec 30, 2013 at 15:58
  • I know, but I can't think of what the new code will be. Commented Dec 30, 2013 at 16:00
  • @user2921419: Well, in that case the new code would use the numbers 0 through 4 instead of 1 through 5. Barring that, what is the type of myRow.Item(5)? How is it different from the other items before it? What is the type expected by .Add()? Commented Dec 30, 2013 at 16:02
  • cfr my answer below... but there might be other problems in your code... Commented Dec 30, 2013 at 16:03
  • I've already tried this. The problem is that I get the id column from the access database into the website column of my application. Commented Dec 30, 2013 at 16:06

2 Answers 2

1

I didn't find the problem but I found another way to do the exact same thing.

Public Sub DisplayPasswords() Main.Passes.Items.Clear() Dim cmd As New OleDb.OleDbCommand( _ "SELECT * FROM passwords ORDER BY id", _ con) Dim dr As OleDbDataReader = cmd.ExecuteReader() Do While dr.Read() Dim new_item As New _ ListViewItem(dr.Item("website").ToString) new_item.SubItems.Add(dr.Item("username").ToString) new_item.SubItems.Add(dr.Item("password").ToString) new_item.SubItems.Add(dr.Item("dates").ToString) new_item.SubItems.Add(dr.Item("notes").ToString) Main.Passes.Items.Add(new_item) Loop End Sub 
Sign up to request clarification or add additional context in comments.

Comments

0

As index goes from 0 to n-1 , where n is the number of items, try this :

For Each myRow In dt.Rows Passes.Items.Add(myRow.Item(0)) Passes.Items(Passes.Items.Count - 1).SubItems.Add(myRow.Item(1)) Passes.Items(Passes.Items.Count - 1).SubItems.Add(myRow.Item(2)) Passes.Items(Passes.Items.Count - 1).SubItems.Add(myRow.Item(3)) Passes.Items(Passes.Items.Count - 1).SubItems.Add(myRow.Item(4)) Next 

But I'm not sure to understand what your code is doing, you may encounter other problems...

1 Comment

I've already tried this. The problem is that I get the id column from the access database into the website column of my application.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.