VK LABELS

Sunday, 16 March 2014

Program for Student Information DataBase and Perform the Add, Delete, and Update

PROGRAM FOR STUDENT INFORMATION DATABASE AND PERFORM THE FOLLOWING OPERATIONS: ADDITION, DELETION, AND UPDATION:

USING ORACLE DATABASE:
FORM1:

Imports System.Data
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Public Class Form1

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Form2.Show()
    End Sub
   
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MsgBox("PLEASE TYPE NAME")
        ElseIf TextBox2.Text = "" Then
            MsgBox("PLEASE TYPE DATE OF BIRTH")
        ElseIf TextBox3.Text = "" Then
            MsgBox("PLEASE TYPE ROLL NO")
        ElseIf TextBox4.Text = "" Then
            MsgBox("PLEASE TYPE REGNO")
        ElseIf TextBox5.Text = "" Then
            MsgBox("PLEASE TYPE CLASS")
        ElseIf TextBox6.Text = "" Then
            MsgBox("PLEASE TYPE PERCENTAGE")
        Else
            Dim oradb As String = "Data Source=XE;User Id=HR;Password=password;"
            Dim conn As New OracleConnection(oradb)
            conn.Open()
            Dim cmd As New OracleCommand
            cmd.Connection = conn
            cmd.CommandText = "insert into SDB values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "')"
            cmd.CommandType = CommandType.Text
            cmd.ExecuteNonQuery()
            MsgBox("Record is successfully stored")
            conn.Dispose()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Form3.Show()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Form4.Show()
    End Sub
   
    End Class

FORM 3:

Imports System.Data
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Public Class Form3

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MsgBox("PLEASE TYPE REGISTER NUMBER")
        Else
            Dim oradb As String = "Data Source=XE;User Id=HR;Password=password;"
            Dim conn As New OracleConnection(oradb)
            conn.Open()
            Dim cmd As New OracleCommand
            Dim cmd1 As New OracleCommand
            cmd.Connection = conn
            cmd.CommandText = "SELECT * FROM SDB WHERE REGNO='" & TextBox1.Text & "'"
            cmd.CommandType = CommandType.Text
            Dim dr As OracleDataReader
            dr = cmd.ExecuteReader()
            If dr.Read() Then
                TextBox1.Text = dr("REGNO")
                cmd1.Connection = conn
                cmd1.CommandText = "delete from SDB WHERE REGNO='" & TextBox1.Text & "'"
                cmd1.CommandType = CommandType.Text
                cmd1.ExecuteNonQuery()
                MsgBox("Record is successfully deleted")
                conn.Dispose()
            Else
                MsgBox("REGISTER NUMBER IS NOT AVOILABLE")
            End If
        End If
    End Sub

    End Class

FORM 4:

Imports System.Data
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Public Class Form4

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MsgBox("PLEASE TYPE REGISTER NUMBER")
        Else
            Panel1.Visible = True
        End If
    End Sub

    Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Panel1.Visible = False
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If TextBox2.Text = "" Then
            MsgBox("PLEASE TYPE NAME")
        ElseIf TextBox3.Text = "" Then
            MsgBox("PLEASE TYPE DOB")
        ElseIf TextBox4.Text = "" Then
            MsgBox("PLEASE TYPE ROLL NO")
        ElseIf TextBox5.Text = "" Then
            MsgBox("PLEASE TYPE REG NO")
        ElseIf TextBox6.Text = "" Then
            MsgBox("PLEASE TYPE CLASS")
        ElseIf TextBox7.Text = "" Then
            MsgBox("PLEASE TYPE PERCENTAGE")
        Else
            Dim oradb As String = "Data Source=XE;User Id=HR;Password=password;"
            Dim conn As New OracleConnection(oradb)
            conn.Open()
            Dim cmd As New OracleCommand
            cmd.Connection = conn
            cmd.CommandText = "UPDATE SDB SET NAME='" & TextBox2.Text & "',DOB='" & TextBox3.Text & "',ROLLNO='" & TextBox4.Text & "',REGNO='" & TextBox5.Text & "',CLASS='" & TextBox6.Text & "',PERCENTAGE='" & TextBox7.Text & "' WHERE REGNO='" & TextBox1.Text & "'"
            cmd.CommandType = CommandType.Text
            cmd.ExecuteNonQuery()
            MsgBox("Record is Successfully Edited")
            conn.Dispose()
        End If
    End Sub
End Class

USING MS SQL DATABASE:

FORM 1:

Imports System.Data
Imports System.Data.SqlClient
Public Class Form1

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Form2.Show()
    End Sub
           
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MsgBox("PLEASE TYPE NAME")
        ElseIf TextBox2.Text = "" Then
            MsgBox("PLEASE TYPE DATE OF BIRTH")
        ElseIf TextBox3.Text = "" Then
            MsgBox("PLEASE TYPE ROLL NO")
        ElseIf TextBox4.Text = "" Then
            MsgBox("PLEASE TYPE REGNO")
        ElseIf TextBox5.Text = "" Then
            MsgBox("PLEASE TYPE CLASS")
        ElseIf TextBox6.Text = "" Then
            MsgBox("PLEASE TYPE PERCENTAGE")
        Else
            Dim sqldb As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
            Dim con As New SqlConnection(sqldb)
            con.Open()
            Dim cmd As New SqlCommand
            cmd.Connection = con
            cmd.CommandText = "insert into Table1 values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "')"
            cmd.CommandType = CommandType.Text
            cmd.ExecuteNonQuery()
            MsgBox("Record is successfully stored")
            con.Dispose()
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Form3.Show()
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Form4.Show()
    End Sub

End Class

FORM 3:

Imports System.Data
Imports System.Data.SqlClient
Public Class Form3

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MsgBox("PLEASE TYPE REGISTER NUMBER")
        Else
            Dim sqldb As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
            Dim conn As New SqlConnection(sqldb)
            conn.Open()
            Dim cmd1 As New SqlCommand
            cmd1.Connection = conn
            cmd1.CommandText = "delete from Table1 WHERE REGNO='" & TextBox1.Text & "'"
            cmd1.CommandType = CommandType.Text
            cmd1.ExecuteNonQuery()
            MsgBox("Record is successfully deleted")
            conn.Dispose()
        End If
    End Sub

    End Class

FORM 4:
Imports System.Data
Imports System.Data.SqlClient
Public Class Form4

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MsgBox("PLEASE TYPE REGISTER NUMBER")
        Else
            Panel1.Visible = True
        End If
    End Sub

    Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Panel1.Visible = False
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If TextBox2.Text = "" Then
            MsgBox("PLEASE TYPE NAME")
        ElseIf TextBox3.Text = "" Then
            MsgBox("PLEASE TYPE DOB")
        ElseIf TextBox4.Text = "" Then
            MsgBox("PLEASE TYPE ROLL NO")
        ElseIf TextBox5.Text = "" Then
            MsgBox("PLEASE TYPE REG NO")
        ElseIf TextBox6.Text = "" Then
            MsgBox("PLEASE TYPE CLASS")
        ElseIf TextBox7.Text = "" Then
            MsgBox("PLEASE TYPE PERCENTAGE")
        Else
            Dim sqldb As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
            Dim conn As New SqlConnection(sqldb)
            conn.Open()
            Dim cmd As New SqlCommand
            cmd.Connection = conn
            cmd.CommandText = "UPDATE Table1 SET NAME='" & TextBox2.Text & "',DOB='" & TextBox3.Text & "',ROLLNO='" & TextBox4.Text & "',REGNO='" & TextBox5.Text & "',CLASS='" & TextBox6.Text & "',PERCENTAGE='" & TextBox7.Text & "' WHERE REGNO='" & TextBox1.Text & "'"
            cmd.CommandType = CommandType.Text
            cmd.ExecuteNonQuery()
            MsgBox("Record is Successfully Edited")
            conn.Dispose()
        End If
    End Sub


    End Class

No comments:

Post a Comment