'add three command button named cmdupdate,cmdadd and cmddelete
'and two text box named txt1 and txt2
'and MS Access file with table name tblContacts with two field name and department



Code:
Imports System.Data

Public Class Form1
    Dim ds As New DataSet
    Dim da As New OleDb.OleDbDataAdapter
    Dim sql As String 

Private Sub cmdupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdupdate.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)
        ds.Tables("AddressBook").Rows(Val(IDTextBox.Text)).Item(1) = txt1.Text
        ds.Tables("AddressBook").Rows(Val(IDTextBox.Text)).Item(2) = txt2.Text
        da.Update(ds, "AddressBook")
        MsgBox("hi", MsgBoxStyle.MsgBoxHelp, "hello")


    End Sub

    Private Sub cmdadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdadd.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)
        Dim dsNewRow As DataRow
        dsNewRow = ds.Tables("AddressBook").NewRow()
        dsNewRow.Item("FirstName") = txt1.Text
        dsNewRow.Item("Surname") = txt2.Text
        ds.Tables("AddressBook").Rows.Add(dsNewRow)
        da.Update(ds, "AddressBook")
        MsgBox("New Record added to the Database")
    End Sub

    Private Sub cmddelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmddelete.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)

        If (MessageBox.Show("r u sure u want to delete", "Warning", MessageBoxButtons.OKCancel) = vbOK) Then
            ds.Tables("AddressBook").Rows(Val(IDTextBox.Text)).Delete()
        Else


        End If
        da.Update(ds, "AddressBook")
    End Sub

End Class

Last edited by shabbir; 14Oct2008 at 16:15.. Reason: Code block