0% found this document useful (0 votes)
25 views4 pages

Prac 27

1. The document contains code for creating a Windows form application to manage an employee database using OleDb. 2. It includes code to insert, update, delete, and search records from the database table. 3. The form contains textboxes, buttons, and a datagrid to display records for interacting with the employee table in the backend database.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views4 pages

Prac 27

1. The document contains code for creating a Windows form application to manage an employee database using OleDb. 2. It includes code to insert, update, delete, and search records from the database table. 3. The form contains textboxes, buttons, and a datagrid to display records for interacting with the employee table in the backend database.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Prac 27 (1) :

Imports System.Data.OleDb
Public Class Form1
Dim con As OleDbConnection
Dim ds As New DataSet
Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source
=C:\Users\student\Documents\db25.mdb")
con.Open()
Dim InsertString As String
InsertString = "Insert into student([Roll No],Name,Marks)values('" +
txtRollNo.Text + "','" + txtName.Text + "','" + txtMarks.Text + "')"
Dim cmd As New OleDbCommand(InsertString, con)
cmd.ExecuteNonQuery()
MsgBox("Record Successfully Inserted")
con.Close()
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source
=C:\Users\student\Documents\db25.mdb")
con.Open()
Dim cmd As New OleDbCommand("Select * from student", con)
Dim da As New OleDbDataAdapter(cmd)
DataGrid1.CaptionText = "Student Marks"
da.Fill(ds, "student")
DataGrid1.DataSource = ds
DataGrid1.DataMember = "student"
con.Close()
End Sub

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


Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source
=C:\Users\student\Documents\db25.mdb")
con.Open()
Dim DeleteString As String
DeleteString = "Delete from student where [Roll no] =" + txtRollNo.Text
Dim cmd As New OleDbCommand(DeleteString, con)
cmd.ExecuteNonQuery()
MsgBox("Record Successfully Deleted")
con.Close()
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click


Close()
End Sub
End Class
Prac 27 (2) :
Imports System.Data.OleDb
Public Class Form1
Dim con As OleDbConnection
Dim ds As New DataSet
Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\student\Documents\Emp01.mdb")
con.Open()
If txtNo.Text = "" Then
MsgBox("Please Enter Employee Number")
Else
Dim InsertString As String
InsertString = "Insert into
employee(emp_no,emp_name,emp_add,emp_date)values('" + txtNo.Text + "','" + txtName.Text +
"','" + txtAdd.Text + "','" + txtDOJ.Text + "')"
Dim cmd As New OleDbCommand(InsertString, con)
cmd.ExecuteNonQuery()
MsgBox("Record Successfully Inserted")
txtNo.Clear()
txtName.Clear()
txtAdd.Clear()
txtDOJ.Clear()
con.Close()
End If
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


Try
Using con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\student\Documents\Emp01.mdb")
con.Open()
If txtNo.Text <> "" Then
Dim DeleteString As String = "Delete from employee where emp_no = ?"
Using cmd As New OleDbCommand(DeleteString, con)
cmd.Parameters.AddWithValue("@emp_no", txtNo.Text)
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
If rowsAffected > 0 Then
MsgBox("Record Successfully Deleted")
txtNo.Clear()
txtAdd.Focus()
Else
MsgBox("No record found with the provided employee number")
End If
End Using
Else
MsgBox("Please enter employee number")
End If
End Using
Catch ex As Exception
MsgBox("Error: " & ex.Message)
End Try
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click


Try
Using con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\student\Documents\Emp01.mdb")
con.Open()
If txtNo.Text <> "" Then
Dim UpdateString As String = "Update employee set emp_name=?,
emp_add=?, emp_date=? where emp_no =?"
Using cmd As New OleDbCommand(UpdateString, con)
cmd.Parameters.AddWithValue("@emp_name", txtName.Text)
cmd.Parameters.AddWithValue("@emp_add", txtAdd.Text)
cmd.Parameters.AddWithValue("@emp_date", txtDOJ.Text)
cmd.Parameters.AddWithValue("@emp_no", txtNo.Text)
cmd.ExecuteNonQuery()
MsgBox("Record successfully Updated")
txtNo.Clear()
txtName.Clear()
txtAdd.Clear()
txtDOJ.Clear()
End Using
Else
MsgBox("Please Enter Employment Number")
End If
End Using
Catch ex As Exception
MsgBox("Error: " & ex.Message)
End Try
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click


Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\student\Documents\Emp01.mdb")
con.Open()
Dim cmd As New OleDbCommand("Select * from employee", con)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
DataGrid1.CaptionText = "Employee Record"
da.Fill(ds, "employee")
DataGrid1.DataSource = ds
DataGrid1.DataMember = "employee"
con.Close()
End Sub

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


If txtNo.Text = "" Then
MsgBox("Please Enter Employee Number")
Else
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\student\Documents\Emp01.mdb")
con.Open()
Dim cmd As New OleDbCommand("Select * from employee where emp_no like'" +
txtNo.Text + "'", con)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
DataGrid1.CaptionText = "Employee Record"
da.Fill(ds, "employee")
DataGrid1.DataSource = ds.Tables("employee")
da.Dispose()
con.Close()
txtNo.Clear()
txtNo.Focus()
End If
End Sub
End Class

You might also like