Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(VB2008) Tutorial Listview + Access Database

Status
Not open for further replies.

RadjeshNL

Technical User
Sep 1, 2008
32
NL
Hi,

Just beginning vb2008 after a few years of VB6 and also bought "Visual Basic 2008 Step By Step". Imho: not a very informative. It just handles the standard, easy things. Nice to have as a reference, but that's all.

The problem is that I can't find a tutorial about the ListView in combination with an Access Database. Does anyone have a small piece of code or a tutorial where I can see how that is accomplished?

Thanks in advance.
 
Thanks for the tip :)

Code:
Dim ds As New DataSet, da As OleDb.OleDbDataAdapter, dt As DataTable, dr As DataRow

        da = New OleDb.OleDbDataAdapter("SELECT * FROM data", conn)
        [COLOR=red]da.Fill(ds)[/color]

OleDbExeption was unhandled...
 
Found a solution after several hours and adding 3 samples together and some rewriting:

Code:
Dim dbPath As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Application.StartupPath & "\data.mdb;"
        Dim conn As New OleDb.OleDbConnection(dbPath)
        conn.Open()

        MsgBox("verbinding open")

        Dim ole_cmd As New OleDb.OleDbCommand("SELECT * FROM Contacten", conn)
        Dim data_reader As OleDb.OleDbDataReader = ole_cmd.ExecuteReader(CommandBehavior.CloseConnection)

        lstvLijst.Items.Clear()

        Do While data_reader.Read()
            Dim new_item As New  _
ListViewItem(data_reader.Item("Voornaam").ToString)
new_item.SubItems.Add(data_reader.Item("Field1").ToString)
new_item.SubItems.Add(data_reader.Item("Field2").ToString)
new_item.SubItems.Add(data_reader.Item("Field3").ToString)
'   ..... etc.....
            lstvLijst.Items.Add(new_item)
        Loop

        conn.Close()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top