Imports System.Data.OleDb
Imports System.Windows.Forms
Imports System.Data.SqlClient


Public Class Form1
    Inherits System.Windows.Forms.Form

    Dim oconn As New OleDbConnection("PROVIDER=Microsoft.Jet.OleDB.4.0;Data Source=c:\vb\bieren.mdb")
    Dim strSql As String = "SELECT * FROM bieren"
    Dim ocomm As New OleDbCommand(strSql)
    Dim oDa = New OleDbDataAdapter(strSql, oconn)
    Dim oDs As New DataSet()
    Dim i As Integer = 0
    Dim oCB As New OleDbCommandBuilder(oDa)
    Dim aantal As Integer

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()


        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents txtnaam As System.Windows.Forms.TextBox
    Friend WithEvents lblid As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txtnummer As System.Windows.Forms.TextBox
    Friend WithEvents btnverwijder As System.Windows.Forms.Button
    Friend WithEvents btnupdate As System.Windows.Forms.Button
    Friend WithEvents btnnew As System.Windows.Forms.Button
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Friend WithEvents btnaantal As System.Windows.Forms.Button
    Friend WithEvents lbllaatste As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.Button2 = New System.Windows.Forms.Button()
        Me.txtnaam = New System.Windows.Forms.TextBox()
        Me.txtnummer = New System.Windows.Forms.TextBox()
        Me.lblid = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.btnverwijder = New System.Windows.Forms.Button()
        Me.btnupdate = New System.Windows.Forms.Button()
        Me.btnnew = New System.Windows.Forms.Button()
        Me.btnExit = New System.Windows.Forms.Button()
        Me.btnaantal = New System.Windows.Forms.Button()
        Me.lbllaatste = New System.Windows.Forms.Label()
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(120, 152)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(72, 24)
        Me.Button1.TabIndex = 4
        Me.Button1.Text = "Vorige"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(224, 152)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(72, 24)
        Me.Button2.TabIndex = 5
        Me.Button2.Text = "Volgende"
        '
        'txtnaam
        '
        Me.txtnaam.Location = New System.Drawing.Point(144, 112)
        Me.txtnaam.Name = "txtnaam"
        Me.txtnaam.Size = New System.Drawing.Size(168, 20)
        Me.txtnaam.TabIndex = 6
        Me.txtnaam.Text = ""
        '
        'txtnummer
        '
        Me.txtnummer.Location = New System.Drawing.Point(144, 80)
        Me.txtnummer.Name = "txtnummer"
        Me.txtnummer.Size = New System.Drawing.Size(168, 20)
        Me.txtnummer.TabIndex = 8
        Me.txtnummer.Text = ""
        '
        'lblid
        '
        Me.lblid.Location = New System.Drawing.Point(32, 80)
        Me.lblid.Name = "lblid"
        Me.lblid.Size = New System.Drawing.Size(80, 24)
        Me.lblid.TabIndex = 9
        Me.lblid.Text = "Bier nummer"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(32, 112)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(80, 24)
        Me.Label1.TabIndex = 10
        Me.Label1.Text = "naam"
        '
        'btnverwijder
        '
        Me.btnverwijder.Location = New System.Drawing.Point(64, 24)
        Me.btnverwijder.Name = "btnverwijder"
        Me.btnverwijder.TabIndex = 11
        Me.btnverwijder.Text = "Delete"
        '
        'btnupdate
        '
        Me.btnupdate.Location = New System.Drawing.Point(288, 24)
        Me.btnupdate.Name = "btnupdate"
        Me.btnupdate.Size = New System.Drawing.Size(75, 24)
        Me.btnupdate.TabIndex = 12
        Me.btnupdate.Text = "Update"
        '
        'btnnew
        '
        Me.btnnew.Location = New System.Drawing.Point(168, 24)
        Me.btnnew.Name = "btnnew"
        Me.btnnew.Size = New System.Drawing.Size(88, 24)
        Me.btnnew.TabIndex = 13
        Me.btnnew.Text = "New"
        '
        'btnExit
        '
        Me.btnExit.Location = New System.Drawing.Point(168, 208)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.Size = New System.Drawing.Size(64, 24)
        Me.btnExit.TabIndex = 14
        Me.btnExit.Text = "Exit"
        '
        'btnaantal
        '
        Me.btnaantal.Location = New System.Drawing.Point(48, 208)
        Me.btnaantal.Name = "btnaantal"
        Me.btnaantal.Size = New System.Drawing.Size(72, 24)
        Me.btnaantal.TabIndex = 15
        Me.btnaantal.Text = "Aantal"
        '
        'lbllaatste
        '
        Me.lbllaatste.Location = New System.Drawing.Point(336, 80)
        Me.lbllaatste.Name = "lbllaatste"
        Me.lbllaatste.Size = New System.Drawing.Size(64, 48)
        Me.lbllaatste.TabIndex = 16
        Me.lbllaatste.Text = "Klik hier voor eerste/laatste record"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(416, 245)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lbllaatste, Me.btnaantal, Me.btnExit, Me.btnnew, Me.btnupdate, Me.btnverwijder, Me.Label1, Me.lblid, Me.txtnummer, Me.txtnaam, Me.Button2, Me.Button1})
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private Sub ConnectDataBase_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'het schema da de dataset zat automatisch gegenereerd worden op basis vd database
        oDa.MissingSchemaAction = MissingSchemaAction.AddWithKey
        oDs.Clear()
        oDa.Fill(oDs, "bieren")

        Dim dr As DataRow
        dr = oDs.Tables("bieren").Rows(i)
        txtnummer.Text = dr("Biernr")
        txtnaam.Text = dr("naam")
        aantal = oDs.Tables("Bieren").Rows().Count()

    End Sub



    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim dr As DataRow
        i += 1
        dr = oDs.Tables("bieren").Rows(i)
        txtnummer.Text = dr("Biernr")
        txtnaam.Text = dr("naam")


    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dr As DataRow
        i += -1
        If i < 0 Then
            i = 0
        End If

        dr = oDs.Tables("bieren").Rows(i)
        txtnummer.Text = dr("Biernr")
        txtnaam.Text = dr("naam")

    End Sub

    Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
        Dim rij As DataRow
        rij = oDs.Tables("Bieren").Rows.Find(txtnummer.Text())
        If rij Is Nothing Then
            MessageBox.Show("Bier niet gevonden!")
        Else
            rij("naam") = txtnaam.Text()
            rij.EndEdit()
        End If

    End Sub



    Private Sub btnverwijder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnverwijder.Click

        Dim rij As DataRow
        rij = oDs.Tables("Bieren").Rows.Find(txtnummer.Text())
        oDs.Tables("Bieren").Rows.Remove(rij)

    End Sub



    Private Sub btnnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnew.Click
        Dim workRow As DataRow = oDs.Tables("Bieren").NewRow()

        workRow("naam") = txtnaam.Text()

        oDs.Tables("Bieren").Rows.Add(workRow)




    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        oDa.Update(oDs, "Bieren")
        Application.Exit()
    End Sub

    Private Sub btnaantal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaantal.Click
        Dim aantal As Integer = oDs.Tables("Bieren").Rows().Count()

        MessageBox.Show("Er bevinden zich: " & aantal & " records in de dataset.", "Records", MessageBoxButtons.OK)


    End Sub

    Private Sub lbllaatste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbllaatste.Click
        Dim drij As DataRow
        drij = oDs.Tables("bieren").Rows(aantal - 1)
        txtnummer.Text = drij("Biernr")
        txtnaam.Text = drij("Naam")

    End Sub
    Private Sub lbllaatste_hover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbllaatste.DoubleClick
        Dim drij As DataRow
        drij = oDs.Tables("bieren").Rows(0)
        txtnummer.Text = drij("Biernr")
        txtnaam.Text = drij("Naam")

    End Sub


End Class
