Imports System.Data.OleDb
Public Class Form1
Dim con As OleDbConnection
Dim da As OleDbDataAdapter
Dim cb As OleDbCommandBuilder
Dim ds As DataSet
Dim dr As DataRow
Dim i As Integer = 0
Dim addflag As Boolean = False
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
da.Update(ds, "emp")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'PractDataSet.emp' table. You can move, or remove it, as needed.
Me.EmpTableAdapter.Fill(Me.PractDataSet.emp)
con = New OleDbConnection("provider=microsoft.jet.oledb.4.0; data source=d:\pract.mdb")
da = New OleDbDataAdapter("select * from emp", con)
cb = New OleDbCommandBuilder(da)
ds = New DataSet
da.Fill(ds, "emp")
End Sub
Sub dispdata()
TextBox1.Text = dr(0)
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
i = 0
dr = ds.Tables("emp").Rows(i)
dispdata()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If i = 0 Then
MsgBox("First Record")
Else
i = i - 1
dr = ds.Tables("emp").Rows(i)
dispdata()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If i = ds.Tables("emp").Rows.Count - 1 Then
MsgBox("Last Record")
Else
i = i + 1
dr = ds.Tables("emp").Rows(i)
dispdata()
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
i = ds.Tables("emp").Rows.Count - 1
dr = ds.Tables("emp").Rows(i)
dispdata()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If Button5.Text = "Add" Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
addflag = True
Button5.Text = "Save"
Button6.Text = "Cancel"
Else
If addflag = True Then
dr = ds.Tables("emp").NewRow
dr(0) = TextBox1.Text
dr(1) = TextBox2.Text
dr(2) = TextBox2.Text
ds.Tables("emp").Rows.Add(dr)
da.Update(ds, "emp")
addflag = False
Else
dr(0) = TextBox1.Text
dr(1) = TextBox2.Text
dr(2) = TextBox2.Text
da.Update(ds, "emp")
End If
Button5.Text = "Add"
Button6.Text = "Edit"
MsgBox("Saved Record")
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If Button6.Text = "Edit" Then
Button5.Text = "Save"
Button6.Text = "Cancel"
addflag = False
Else
dispdata()
Button5.Text = "Add"
Button6.Text = "Edit"
End If
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If MessageBox.Show("Are you sure?", "confirmation", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
ds.Tables("emp").Rows(i).Delete()
If i = ds.Tables("emp").Rows.Count - 1 Then
i = i - 1
End If
da.Update(ds, "emp")
dr = ds.Tables("emp").Rows(i)
dispdata()
End If
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Me.Close()
End Sub
End Class
from [email]shivpuje.deepali@gmail.com[/email]