Private Sub butÄndern_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
objCB = New OleDb.OleDbCommandBuilder(objDataAdapter)
objDataAdapter.UpdateCommand = objCB.GetUpdateCommand
Try
Me.BindingContext(Me.objDataView).EndCurrentEdit()
If objDataTable.GetChanges Is Nothing Then Return
objDataAdapter.Update(objDataTable.GetChanges)
objDataTable.AcceptChanges()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button2.Click
objDataAdapter.Fill(objDataTable)
Me.objDataSet.Tables.Add(Me.objDataTable)
objDataView = New DataView(objDataTable)
Me.DataBindings.Add("Text", objDataView, "Nummer")
Me.txtVorname.DataBindings.Add("Text", objDataView, "Vorname")
Me.txtZuname.DataBindings.Add("Text", objDataView, "Nachname")
Me.BindingContext(objDataView).Position = 0
Me.DataGrid1.DataSource = Me.objDataView
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
objDataSet = New DataSet("DataSet")
objDataTable = New DataTable("DataTable")
objConn = New OleDb.OleDbConnection(sCon)
objDataAdapter = New OleDb.OleDbDataAdapter(New OleDb.OleDbCommand( _
"SELECT * FROM Mitarbeiter", objConn))
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button4.Click
Me.BindingContext(objDataView).Position -= 1
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button3.Click
Me.BindingContext(objDataView).Position += 1
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button5.Click
Me.BindingContext(objDataView).Position = 0
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button6.Click
Me.BindingContext(objDataView).Position = Me.BindingContext( _
objDataView).Count
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button7.Click
Me.BindingContext(objDataView).AddNew()
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button8.Click
Me.BindingContext(objDataView).RemoveAt(Me.BindingContext( _
objDataView).Position)
End Sub
End Class(Ende)
Und das Beipiel zu testen, solltest du dir ein Access "Datenbank" mit dem Namen "Mitarbeiter.mdb" anlegen. Diese Datei kopierst du in den "bin" Ordners deines Projektes. Anschliessend legst du eine Tabelle an, welche ebenfalls "Mitarbeiter" heisst. In dieser Tabelle legst du folgende 3 Spalten an:
Nummer (FelddatenTyp: Zahl)
Vorname (FelddatenTyp:Text)
Nachname (FelddatenTyp:Text)
Der Spalte Nummer gibst du den Primärschlüssel (wichtig!).
Dann speichern. Und in deinem Projekt F5 drücken ....  |