i connect my access to vb2010 using adodb.
but i cant display the datas in my listview.
can someone help me to solve my problem. i would really appreaciate any help.
what i need is to get the column per column datas..
like how it is shown in the access. im a freshman college student in cs. Someone pls help me :(

here is my code:

Public Class StockList
    Dim cnn As New ADODB.Connection
    Dim rst As New ADODB.Recordset

    Private Sub StockList_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave
        cnn.Close()
    End Sub

    Private Sub StockList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cnn.Open("DBQ=C:\Users\biboy\Documents\MyInventory.accdb;Driver={Microsoft Access Driver (*.mdb, *.accdb)};uid=;pwd=;")


        rst.Open("select * from Product", cnn, 1, 3)


        ListView1.BeginUpdate()
        ListView1 = (rst.Fields("SKU").Value)
        ListView1 = (rst.Fields("Quantity").Value)
        ListView1 = (rst.Fields("Description").Value)
        ListView1 = (rst.Fields("UOM").Value)
        ListView1 = (rst.Fields("SRP").Value)
        ListView1 = (rst.Fields("Origin").Value)
        ListView1 = (rst.Fields("Department").Value)

        rst.Close()

    End Sub
End Class

Recommended Answers

All 3 Replies

and here is the error im actually getting when i run the program

Try adding ".toString" in front of .Value

Ensure ListView.View = View.Details

'set to details view
ListView1.View = View.Details

Did you already create the columns? If not, add this to your code:

    'Add columns to listview
    ListView1.Columns.Add("SKU")
    ListView1.Columns.Add("Quantity")
    ListView1.Columns.Add("Description")
    ListView1.Columns.Add("UOM")
    ListView1.Columns.Add("SRP")
    ListView1.Columns.Add("Origin")
    ListView1.Columns.Add("Department")

To add the data to ListView1:

        'increment through each record in recordset
        'and add data to ListView1
        For i As Integer = 0 To rst.RecordCount - 1

            Dim item As ListViewItem

            'add new row and add value of "SKU" to first column
            item = New ListViewItem(rst.Fields.Item("SKU").Value.ToString(), 0)

            'add value to 2nd column
            item.SubItems.Add(rst.Fields.Item("Quantity").Value.ToString())

            'add value to 3rd column
            item.SubItems.Add(rst.Fields.Item("Description").Value.ToString())

            'add value to 4th column
            item.SubItems.Add(rst.Fields.Item("SRP").Value.ToString())

            'add item to ListView1
            ListView1.Items.Add(item)

            'move to next record
            rst.MoveNext()
        Next
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.