DB Prog Print

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Public Class Form1

Dim cn As New Data.OleDb.OleDbConnection

Private Sub Form1_Load(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles MyBase.Load
Me.StudTableAdapter.Fill(Me.SampledbDataSet2.Stud)
cn.ConnectionString =
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\
sampledbprog\sampledbprog\sampledb.accdb"
cn.Open()
End Sub

Private Sub butfind_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles butfind.Click
If Len(Trim(txtfind.Text)) = 0 Then
MsgBox("Please Enter RegNO to Find", MsgBoxStyle.OkOnly)
Else
Dim cmd As New System.Data.OleDb.OleDbCommand("select * from
Stud where SRegno='" & txtfind.Text & "'", cn)
Dim dr As System.Data.OleDb.OleDbDataReader
dr = cmd.ExecuteReader()
If dr.Read() Then
txtregno.Text = dr(0).ToString()
txtname.Text = dr(1).ToString()
txtcourse.Text = dr(2).ToString()
Else
MsgBox("NOT Found...!", MsgBoxStyle.Exclamation)
txtregno.Text = ""
txtname.Text = ""
txtcourse.Text = ""
txtfind.Text = ""
End If
dr.Close()
End If
End Sub

Private Sub Button5_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles Button5.Click
End
End Sub

Private Sub Button1_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles Button1.Click
If Len(Trim(txtregno.Text)) = 0 Or Len(Trim(txtname.Text)) =
0 Or Len(Trim(txtcourse.Text)) = 0 Then
MsgBox("Please Fill Date to insert")
txtregno.Focus()
Else
Dim cmd2 As New System.Data.OleDb.OleDbCommand("select *
from Stud where SRegno='" & txtfind.Text & "'", cn)
Dim dr As System.Data.OleDb.OleDbDataReader
dr = cmd2.ExecuteReader()
If dr.Read() Then
MsgBox("Reg No Already Exists..")
clear()
Exit Sub
Else
Dim cmd As New System.Data.OleDb.OleDbCommand("insert into
Stud values('" & txtregno.Text & "','" & txtname.Text &
"','" & txtcourse.Text & "')", cn)
cmd.ExecuteNonQuery()
MsgBox("Date inserted Successfully")
clear()
End If
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles Button2.Click
Dim qry As String
If Len(Trim(txtregno.Text)) = 0 Or Len(Trim(txtname.Text)) =
0 Then
MsgBox("Please Fill the Date to Edit", MsgBoxStyle.OkOnly)
Else
If MsgBox("do U want to modify?..", MsgBoxStyle.YesNo) =
MsgBoxResult.Yes Then
qry = "Update Stud set SCourse='" & txtcourse.Text &
"',SName=' " & txtname.Text & " ' where SRegno='" &
txtregno.Text & "' "
Dim cmd As New System.Data.OleDb.OleDbCommand(qry, cn)
cmd.ExecuteNonQuery()
MsgBox("Data Modified Successfully", MsgBoxStyle.OkOnly)
clear()
End If
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles Button3.Click
Dim qry As String
If MsgBox("ARE U WANT TO DELETE?...", MsgBoxStyle.YesNo) =
MsgBoxResult.Yes Then
qry = "delete from Stud where SRegno='" & txtfind.Text & "'"
Dim cmd As New System.Data.OleDb.OleDbCommand(qry, cn)
cmd.ExecuteNonQuery()
MsgBox("DELETED")
clear()
End If
End Sub

Private Function CheckNumber(ByVal rno As String)


Dim f As Boolean
Dim cmd As New System.Data.OleDb.OleDbCommand("select * from
Stud where SRegno='" & txtregno.Text & "'", cn)
Dim dr As System.Data.OleDb.OleDbDataReader
dr = cmd.ExecuteReader()
If dr.Read() Then
f = True
Else
f = False
End If
dr.Close()
CheckNumber = f
clear()
End Function

Private Function clear()


txtcourse.Text = ""
txtfind.Text = ""
txtname.Text = ""
txtregno.Text = ""
End Function

Private Sub Button4_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles Button4.Click
clear()
End Sub
End Class

form1
Public Class Form1
Dim cn As New Data.OleDb.OleDbConnection
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 'SampledbDataSet2.Stud'
table. You can move, or remove it, as needed.
Me.StudTableAdapter.Fill(Me.SampledbDataSet2.Stud)
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=D:\sampledbprog\sampledbprog\sampledb.accdb"
'cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=D:\sampledbprog\sampledbprog\Sampledb.mdf"
cn.Open()
End Sub

Private Sub butfind_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles butfind.Click
If Len(Trim(txtfind.Text)) = 0 Then
MsgBox("Please Enter RegNO to Find", MsgBoxStyle.OkOnly)
Else
Dim cmd As New System.Data.OleDb.OleDbCommand("select * from Stud
where SRegno='" & txtfind.Text & "'", cn)
Dim dr As System.Data.OleDb.OleDbDataReader
dr = cmd.ExecuteReader()
If dr.Read() Then
txtregno.Text = dr(0).ToString()
txtname.Text = dr(1).ToString()
txtcourse.Text = dr(2).ToString()
Else
MsgBox("NOT Found...!", MsgBoxStyle.Exclamation)
txtregno.Text = ""
txtname.Text = ""
txtcourse.Text = ""
txtfind.Text = ""
End If
dr.Close()
End If
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click
End

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
If Len(Trim(txtregno.Text)) = 0 Or Len(Trim(txtname.Text)) = 0 Or
Len(Trim(txtcourse.Text)) = 0 Then
MsgBox("Please Fill Date to insert")
txtregno.Focus()
Else
Dim cmd2 As New System.Data.OleDb.OleDbCommand("select * from Stud
where SRegno='" & txtfind.Text & "'", cn)
Dim dr As System.Data.OleDb.OleDbDataReader
dr = cmd2.ExecuteReader()
If dr.Read() Then
MsgBox("Reg No Already Exists..")
clear()
Exit Sub
Else
Dim cmd As New System.Data.OleDb.OleDbCommand("insert into
Stud values('" & txtregno.Text & "','" & txtname.Text & "','" & txtcourse.Text
& "')", cn)
cmd.ExecuteNonQuery()
MsgBox("Date inserted Successfully")
clear()
End If
End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Dim qry As String
If Len(Trim(txtregno.Text)) = 0 Or Len(Trim(txtname.Text)) = 0 Then
MsgBox("Please Fill the Date to Edit", MsgBoxStyle.OkOnly)
Else
If MsgBox("do U want to modify?..", MsgBoxStyle.YesNo) =
MsgBoxResult.Yes Then
qry = "Update Stud set SCourse='" & txtcourse.Text &
"',SName=' " & txtname.Text & " ' where SRegno='" & txtregno.Text & "' "
Dim cmd As New System.Data.OleDb.OleDbCommand(qry, cn)
cmd.ExecuteNonQuery()
MsgBox("Data Modified Successfully", MsgBoxStyle.OkOnly)
clear()
End If
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Dim qry As String
If MsgBox("ARE U WANT TO DELETE?...", MsgBoxStyle.YesNo) =
MsgBoxResult.Yes Then
qry = "delete from Stud where SRegno='" & txtfind.Text & "'"
Dim cmd As New System.Data.OleDb.OleDbCommand(qry, cn)
cmd.ExecuteNonQuery()
MsgBox("DELETED")
clear()
End If
End Sub
Private Function CheckNumber(ByVal rno As String)
Dim f As Boolean
Dim cmd As New System.Data.OleDb.OleDbCommand("select * from Stud
where SRegno='" & txtregno.Text & "'", cn)
Dim dr As System.Data.OleDb.OleDbDataReader
dr = cmd.ExecuteReader()
If dr.Read() Then
f = True
Else
f = False
End If
dr.Close()
CheckNumber = f
clear()
End Function
Private Function clear()
txtcourse.Text = ""
txtfind.Text = ""
txtname.Text = ""
txtregno.Text = ""
End Function

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
clear()
End Sub
End Class

form2
Imports System.Data.SqlClient
Public Class Form2
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Dim rs As SqlDataReader
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
cn = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=D:\
sampledbprog\sampledbprog\Sampledb.mdf;Integrated Security=True;Connect
Timeout=30;User Instance=True")
cn.Open()
End Sub

Private Function CheckNumber(ByVal rno As String)


Dim f As Boolean
cmd = New SqlCommand("select * from Stud where SRegno='" & rno & "'",
cn)
rs = cmd.ExecuteReader()
If rs.Read() Then
f = True
Else
f = False
End If
rs.Close()
CheckNumber = f
End Function

Function clearForm()
txtregno.Text = ""
txtname.Text = ""
txtfind.Text = ""
txtcourse.Text = ""
Return 0
End Function

Function checkAvail(ByVal rno As String)


Dim count = 0
cmd = New SqlCommand("select * from Stud where SRegno='" &
txtfind.Text & "'", cn)
rs = cmd.ExecuteReader()
While rs.Read
count = 1
End While
rs.Close()
cmd.Dispose()
Return count
End Function

Private Sub butfind_Click_1(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles butfind.Click
Dim count = 0
cmd = New SqlCommand("select * from Stud where SRegno='" &
txtfind.Text & "'", cn)
rs = cmd.ExecuteReader()
While rs.Read
count = 1
txtregno.Text = rs(0)
txtname.Text = rs(1)
txtcourse.Text = rs(2)
End While
rs.Close()
cmd.Dispose()
If count = 1 Then
'txtregno.Enabled = False
Else
MsgBox("Record Not Found")
End If
End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
If checkAvail(txtregno.Text) = 0 Then
cmd = New SqlCommand("insert into Stud(SRegno, SName, SCourse)
values('" & txtregno.Text & "','" & txtname.Text & "','" & txtcourse.Text &
"')", cn)
cmd.ExecuteNonQuery()
cmd.Dispose()
MsgBox("Data Stored Succesfully")
clearForm()
Else
MsgBox("Record Already Existed!")
clearForm()
End If
End Sub

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
cmd = New SqlCommand("update Stud set SName='" & txtname.Text & "',
SCourse='" & txtcourse.Text & "' where SRegno='" & txtregno.Text & "'", cn)
cmd.ExecuteNonQuery()
cmd.Dispose()
MsgBox("Data Updated")
clearForm()
txtregno.Enabled = True
End Sub

Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
cmd = New SqlCommand("delete from Stud where SRegno='" & txtfind.Text
& "'", cn)
cmd.ExecuteNonQuery()
cmd.Dispose()
MsgBox("Record Deleted")
clearForm()
txtregno.Enabled = True
End Sub

Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
clearForm()
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click
Me.Close()
End Sub

Private Sub txtcourse_TextChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles txtcourse.TextChanged

End Sub

Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Label3.Click

End Sub

Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles GroupBox1.Enter

End Sub
End Class
form3
Imports System.Data.SqlClient
Public Class Form3
Dim cn As System.Data.SqlClient.SqlConnection
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
cn = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=D:\
sampledbprog\sampledbprog\Sampledb.mdf;Integrated Security=True;Connect
Timeout=30;User Instance=True")
cn.Open()
End Sub
Private Sub butfind_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butfind.Click
If Len(Trim(txtfind.Text)) = 0 Then
MsgBox("Please Enter RegNO to Find", MsgBoxStyle.OkOnly)
Else
Dim cmd As New System.Data.SqlClient.SqlCommand("select * from
Stud where SRegno='" & txtfind.Text & "'", cn)
Dim dr As System.Data.SqlClient.SqlDataReader
dr = cmd.ExecuteReader()
If dr.Read() Then
txtregno.Text = dr(0).ToString()
txtname.Text = dr(1).ToString()
txtcourse.Text = dr(2).ToString()
Else
MsgBox("NOT Exist...!", MsgBoxStyle.Exclamation)
txtregno.Text = ""
txtname.Text = ""
txtcourse.Text = ""
txtfind.Text = ""
End If
dr.Close()
End If
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click
End

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
If Len(Trim(txtregno.Text)) = 0 Or Len(Trim(txtname.Text)) = 0 Or
Len(Trim(txtcourse.Text)) = 0 Then
MsgBox("Please Fill Date to insert")
txtregno.Focus()
Else
If ChekRegNo(txtregno.Text) = True Then
MsgBox("Already Exist..")
Else
Dim cmd As New System.Data.SqlClient.SqlCommand("insert into
Stud values('" & txtregno.Text & "','" & txtname.Text & "','" & txtcourse.Text
& "')", cn)
cmd.ExecuteNonQuery()
MsgBox("Date inserted Successfully")
clear()
End If

End If

End Sub
Private Function ChekRegNo(ByVal regno As String) As Boolean
Dim a As Boolean
a = False
Dim cmd2 As New System.Data.SqlClient.SqlCommand("select * from Stud
where SRegno='" & regno & "'", cn)
Dim dr As System.Data.SqlClient.SqlDataReader
dr = cmd2.ExecuteReader()
If dr.Read() Then
a = True
End If
dr.Close()
ChekRegNo = a
End Function

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Dim qry As String
If Len(Trim(txtregno.Text)) = 0 Or Len(Trim(txtname.Text)) = 0 Then
MsgBox("Please Fill the Date to Edit", MsgBoxStyle.OkOnly)
Else
If MsgBox("do U want to modify?..", MsgBoxStyle.YesNo) =
MsgBoxResult.Yes Then
qry = "Update Stud set SCourse='" & txtcourse.Text &
"',SName=' " & txtname.Text & " ' where SRegno='" & txtregno.Text & "' "
Dim cmd As New System.Data.SqlClient.SqlCommand(qry, cn)
cmd.ExecuteNonQuery()
MsgBox("Data Modified Successfully", MsgBoxStyle.OkOnly)
clear()
End If
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Dim qry As String
If MsgBox("ARE U WANT TO DELETE?...", MsgBoxStyle.YesNo) =
MsgBoxResult.Yes Then
qry = "delete from Stud where SRegno='" & txtfind.Text & "'"
Dim cmd As New System.Data.SqlClient.SqlCommand(qry, cn)
cmd.ExecuteNonQuery()
MsgBox("DELETED")
clear()
End If
End Sub
Private Function CheckNumber(ByVal rno As String)
Dim f As Boolean
Dim cmd As New System.Data.SqlClient.SqlCommand("select * from Stud
where SRegno='" & txtregno.Text & "'", cn)
Dim dr As System.Data.SqlClient.SqlDataReader
dr = cmd.ExecuteReader()
If dr.Read() Then
f = True
Else
f = False
End If
dr.Close()
CheckNumber = f
clear()
End Function
Private Function clear()
txtcourse.Text = ""
txtfind.Text = ""
txtname.Text = ""
txtregno.Text = ""
End Function
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
clear()
End Sub

End Class

You might also like