Code:-
Imports System.Data.OleDb
Public Class emp
Dim cmd As OleDbCommand
Dim cn As New OleDbConnection Dim ad As New OleDbDataAdapter Dim ds As New DataSet
Dim dr As String
Dim dt As String
Dim i, f, a As Integer
Private Sub emp_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the
Me.Emp_detailsTableAdapter1.Fill(Me._Database1_mdbData Set4.emp_details)
cn = New
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database1.mdb.accdb")
ad = New OleDbDataAdapter("select * from emp_details", cn)
ds = New DataSet() ad.Fill(ds)
End Sub
Sub add(ByVal i As Integer)
TextBox1.Text = ds.Tables(0).Rows(i).Item(0).ToString TextBox2.Text = ds.Tables(0).Rows(i).Item(1).ToString TextBox3.Text = ds.Tables(0).Rows(i).Item(2).ToString TextBox4.Text = ds.Tables(0).Rows(i).Item(3).ToString TextBox5.Text = ds.Tables(0).Rows(i).Item(4).ToString ComboBox1.Text = ds.Tables(0).Rows(i).Item(5).ToString TextBox6.Text = ds.Tables(0).Rows(i).Item(6).ToString TextBox7.Text = ds.Tables(0).Rows(i).Item(7).ToString End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e
As System.Windows.Forms.KeyPressEventArgs) Handles
TextBox2.KeyPress Dim c As Char
c = e.KeyChar
If Not (Char.IsLetter(c) Or Char.IsControl(c)) Then
e.Handled = True
MsgBox("enter only character") End If
End Sub
Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e
As System.Windows.Forms.KeyPressEventArgs) Handles
TextBox3.KeyPress Dim c As Char
c = e.KeyChar
If Not (Char.IsLetter(c) Or Char.IsControl(c)) Then
e.Handled = True
MsgBox("enter only character") End If
End Sub
Private Sub Btn_e_Save_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Btn_e_Save.Click cn.Close() cn.Open()
If (f = 0) Then
If TextBox1.Text = "" Then
ElseIf TextBox2.Text = "" Then
ElseIf TextBox3.Text = "" Then
ElseIf TextBox4.Text = "" Then
ElseIf TextBox5.Text = "" Then
ElseIf ComboBox1.Text = "" Then
ElseIf TextBox6.Text = "" Then
ElseIf TextBox7.Text = "" Then
MsgBox("Please Enter Record") Else
a = MsgBox("Are you want to save new Employee?", vbYesNo + vbQuestion, "SAVE")
If a = vbYes Then
cmd = New OleDbCommand("insert into
emp_details values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" &
TextBox5.Text & "','" & ComboBox1.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "' )", cn)
cmd.ExecuteNonQuery()
MsgBox("Record Save Successfully") End If
End If
End If
End Sub
Private Sub Btn_e_Add_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Btn_e_Add.Click
TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" ComboBox1.SelectedIndex = -1 TextBox5.Text = "" TextBox6.Text = "" TextBox7.Text = "" End Sub
Private Sub Btn_e_Delete_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Btn_e_Delete.Click cn.Close() cn.Open()
If (f = 0) Then
If TextBox1.Text = "" Then
MsgBox("Please Enter Cust_No") ElseIf TextBox1.Text = "" Then
Else
a = MsgBox("Are you want to Delete Employee?", vbYesNo + vbQuestion, "Delete")
If a = vbYes Then
cmd = New OleDbCommand("Delete From emp_details where Emp_ID=" & TextBox1.Text & "", cn) cmd.ExecuteNonQuery()
MsgBox("Record Deleted Successfully.") End If
End If
End If
End Sub
Private Sub Btn_e_Update_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Btn_e_Update.Click cn.Close() cn.Open()
a = "select * from emp_details where emp_ID = '" & TextBox1.Text & "'"
cmd = New OleDbCommand("Update emp_details set Name= ' " & TextBox2.Text & " ',Address= ' " & TextBox3.Text & "
',Contact_No= ' " & TextBox4.Text & " ',Age=' " &
TextBox5.Text & " ', Gender= ' " & ComboBox1.Text & " ' ,J_Date= ' " & TextBox6.Text & " ' ,Total_Sal= ' " &
TextBox7.Text & "' where emp_ID='" & TextBox1.Text & "')", cn) cmd.ExecuteNonQuery()
MsgBox("Record Updated Successfully.") End Sub
Private Sub Btn_e_First_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Btn_e_First.Click
i = 0
Call add(i)
MsgBox("This is first Record") End Sub
Private Sub Btn_e_Pre_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Btn_e_Pre.Click
i = i - 1
If (i >= 0) Then
Call add(i) Else
MsgBox("this is previous record") End If
End Sub
Private Sub Btn_e_Last_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Btn_e_Last.Click
i = ds.Tables(0).Rows.Count - 1 Call add(i)
MsgBox("This is last Record") End Sub
Private Sub Btn_e_Next_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Btn_e_Next.Click i = i + 1
If (i < ds.Tables(0).Rows.Count) Then
Call add(i) Else
MsgBox("this is next record") End If
End Sub
Private Sub Btn_e_Exit_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Btn_e_Exit.Click
Dim a As Integer
Dim OleDbYesNo As Integer
Dim OleDbQuestion As Integer
Dim OleDbYes As Integer
If a = OleDbYes Then
Me.Close() End If
End Sub
Private Sub Btn_e_Search_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Btn_e_Search.Click cn.Close() cn.Open() ds.Clear()
If TextBox1.Text = "" Then
MsgBox("Please Enter emp_details") ElseIf TextBox1.Text = "" Then
Else
ad = New OleDbDataAdapter("select * from emp_details where emp_ID=" & TextBox1.Text & "", cn) ad.Fill(ds)
DataGridView1.DataSource = ds.Tables(0) cn.Close()
End If
Dim cmd1 As New OleDbCommand cn.Close()
cn.Open()
cmd1.Connection = cn
cmd1.CommandText = "select count(*) from emp_details"
Dim m As Integer
m = cmd1.ExecuteScalar a = Val(TextBox1.Text) If a > m Then
MsgBox("No Record") End If
End Sub
End Class