I'm having a problem with loading my MS Access Database. I can get it to load but it won't load in a row. My friend told me to try this but it puts all the information in a column instead of putting all the information spread out accross the row.

Here's my code:

Dim lb_Connection As New OleDb.OleDbConnection
        lb_Connection.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE = pass_database.mdb"

        Dim lb_SelectCommand As New OleDb.OleDbCommand
        lb_SelectCommand.CommandText = "SELECT Title, Username, Password, URL, Notes FROM password_info"
        lb_SelectCommand.Connection = lb_Connection

        Dim lb_DataAdapter As New OleDb.OleDbDataAdapter
        lb_DataAdapter.SelectCommand = lb_SelectCommand

        Dim lb_DataSet As New DataSet
        CType(lb_DataSet, System.ComponentModel.ISupportInitialize).BeginInit()

        lb_DataAdapter.Fill(lb_DataSet)

        Dim lb_DataTable As New DataTable
        lb_DataTable = lb_DataSet.Tables(0)

        For Each db_name In lb_DataTable.Rows
            frmMainPage.lvPasswordInfo.Items.Add(lb_DataTable.Rows(0).Item(0).ToString)
            frmMainPage.lvPasswordInfo.Items.Add(lb_DataTable.Rows(0).Item(1).ToString)
            frmMainPage.lvPasswordInfo.Items.Add(lb_DataTable.Rows(0).Item(2).ToString)
            frmMainPage.lvPasswordInfo.Items.Add(lb_DataTable.Rows(0).Item(3).ToString)
            frmMainPage.lvPasswordInfo.Items.Add(lb_DataTable.Rows(0).Item(4).ToString)
        Next

Also I'll attach an image of what the program does when I load it.

Please help and many thanks in advance.

Recommended Answers

All 2 Replies

See this sample,

ListView1.Columns.Add("One")
        ListView1.Columns.Add("Two")
        ListView1.Columns.Add("Three")

        Dim item As New ListViewItem("v1")
        item.SubItems.Add("A")
        item.SubItems.Add("B")
        ListView1.Items.Add(item)

I had a slight problem with the code you gave me but with the help of my friend I was able to fix it. Here's the modified code that I came up with:

Dim lvitem As New ListViewItem(db_name("Title").ToString)
            lvitem.SubItems.Add(db_name("Username").ToString)
            lvitem.SubItems.Add(db_name("Password").ToString)
            lvitem.SubItems.Add(db_name("URL").ToString)
            lvitem.SubItems.Add(db_name("Notes").ToString)
            frmMainPage.lvPasswordInfo.Items.Add(lvitem)

The problem with your code was that it put text into it. I needed it to pull from my database, adding the .tostring helped solve the problem.
Thanks for your help.

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.