Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Public Class Slip22
Dim con As New SqlConnection("Data Source=.\sqlexpress;Initial Catalog=dbemp1;Integrated Security=True;Pooling=False")
Dim cmd As SqlCommand
Dim da As SqlDataAdapter
Dim dr As SqlDataReader
Dim dt As DataTable
Dim r1 As DataRow
Dim a As Integer
Dim str As String
Public Sub clear()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
con.Open()
str = "insert into emp1 values(" & TextBox1.Text & ",' " & TextBox2.Text & " ',' " & TextBox3.Text & " ',' " & TextBox4.Text & " ')"
cmd = New SqlCommand(str, con)
cmd.ExecuteNonQuery()
MsgBox("Record Save Successfully....")
clear()
con.Close()
fillgrid()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
a = InputBox("enter roll no")
con.Open()
str = "delete from emp1 where eid=" & a & " "
cmd = New SqlCommand(str, con)
cmd.ExecuteNonQuery()
MsgBox("Record Delete Successfully...")
clear()
con.Close()
fillgrid()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
con.Open()
str = "update emp1 set ename=' " & TextBox2.Text & " ',designation=' " & TextBox3.Text & " ',doj= " & TextBox4.Text & " where eid= " & TextBox1.Text & " "
cmd = New SqlCommand(str, con)
cmd.ExecuteNonQuery()
MsgBox("Record Update Successfully...")
clear()
con.Close()
fillgrid()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
con.Open()
a = InputBox("Enter the number")
str = "select * from emp1 where eid=" & a & " "
cmd = New SqlCommand(str, con)
da = New SqlDataAdapter(cmd)
dt = New DataTable
da.Fill(dt)
If dt.Rows.Count = 0 Then
MsgBox("Employee id is not find")
con.Close()
Exit Sub
End If
r1 = dt.Rows(0)
TextBox1.Text = r1.Item(0)
TextBox2.Text = r1.Item(1)
TextBox3.Text = r1.Item(2)
TextBox4.Text = r1.Item(3)
con.Close()
End Sub
Public Sub fillgrid()
con.Open()
str = "select * from emp1"
cmd = New SqlCommand(str, con)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
DataGridView1.Rows.Clear()
While (dr.Read() = True)
DataGridView1.Rows.Add(dr(0), dr(1), dr(2), dr(3))
End While
con.Close()
End Sub
Private Sub Slip22_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
fillgrid()
End Sub
End Class