Question Update Access DB through dataset

grmbl

Active member
Joined
Jun 4, 2009
Messages
32
Location
Belgium
Programming Experience
1-3
Hey,

I'm a bit confused how I can achieve updating my Access DB with my
dataset?

The function below AllesOphalen (=GetEverything) retrieves everything
to a dataset. I'll use this dataset to fill a listview. Listviewitems will be
manipulated through contextmenu.

1. How can I update my dataset? I'll add tags to each listviewitem (=ID)?
2. How can I update the DB with the updated dataset?

This is the code I have so far.
(note this is just a working draft with no error handling or nothing...) ;)

VB.NET:
Imports System.Data.OleDb

Module ACCESS

    Dim cn As OleDbConnection
    Dim ds As New DataSet

    Public Function Ophalen(ByVal tabel As String) As DataTable

        ' connection to DB
        cn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Aliplast\Printers.accdb")
        cn.Open()

        ' Create datatable and add to the dataset
        Dim da As New OleDbDataAdapter("SELECT * FROM " & tabel, cn)
        Dim dt As New DataTable

        dt.TableName = tabel

        da.Fill(dt)

        cn.Close()

        Return dt

    End Function

    Public Function AllesOphalen() As DataSet

        ' Add datatables for each table to dataset
        ds.Tables.Add(Ophalen("tPrinters"))
        ds.Tables.Add(Ophalen("tTellers"))
        ds.Tables.Add(Ophalen("tNotities"))

        ' Add relations in dataset
        Dim rel_tellers As New DataRelation("rel_tellers", ds.Tables("tPrinters").Columns("ID"), ds.Tables("tTellers").Columns("ID"))
        ds.Relations.Add(rel_tellers)
        Dim rel_notities As New DataRelation("rel_notities", ds.Tables("tPrinters").Columns("ID"), ds.Tables("tNotities").Columns("ID"))
        ds.Relations.Add(rel_notities)

        ds.AcceptChanges()

        Return ds

    End Function

End Module

Any help or tips is greatly appreciated!

Grtz,

grmbl!
 
Back
Top