VK LABELS

Saturday, 15 March 2014

Check data in Login Form

Check data in Login Form:

Imports System.Data
Imports Oracle.DataAccess.Client 
Imports Oracle.DataAccess.Types

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If UsernameTextBox.Text = "" Then
            MsgBox("Please Type UserName")
        ElseIf PasswordTextBox.Text = "" Then
            MsgBox("Please Type Password")
        ElseIf UsernameTextBox.Text = "Admin" And PasswordTextBox.Text = "Admin123" Then
            Form2.Show()
        Else
            Using conn = Opencon()
                Dim cmd As New OracleCommand
                cmd.Connection = conn
                cmd.CommandText = "SELECT USERNAME,PASSWORD FROM LOGINDATA WHERE USERNAME='" & UsernameTextBox.Text & "' AND PASSWORD='" & PasswordTextBox.Text & "'"
                cmd.CommandType = CommandType.Text
                Dim dr As OracleDataReader
                dr = cmd.ExecuteReader()
                If dr.Read() Then
                    UsernameTextBox.Text = dr("USERNAME")
                    PasswordTextBox.Text = dr("PASSWORD")
                    Form2.show()
                Else
                    MsgBox("Please Type Correct UserName and PassWord")
                End If
            End Using
        End If
    End Sub


View Database Data Using Data Grid View

View Database Data Using Data Grid View:

Imports System.Data
Imports Oracle.DataAccess.Client 
Imports Oracle.DataAccess.Types


Using conn = root.Opencon()
                Dim cmd As New OracleCommand
                Dim da1 As New OracleDataAdapter("select * from reg_details", conn)
                Dim table1 As New DataTable()
                da1.Fill(table1)
                DataGridView1.DataSource = New BindingSource(table1, Nothing)
End Using


Edit or Update Data in Database Table

Edit or Update Data in Database Table:

Imports System.Data
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If (TextBox1.Text = "") Then
            MsgBox("Please Type RegNo")
       ElseIf (TextBox2.Text = "") Then
            MsgBox("Please Type Name")
        Else
            Using conn = root.Opencon()
                Dim cmd As New OracleCommand
                cmd.Connection = conn
                cmd.CommandText = "SELECT * FROM REG_DETAILS WHERE REGNO='" & TextBox1.Text & "' AND NAME='" & TextBox2.Text & "'"
                cmd.CommandType = CommandType.Text
                Dim drd As OracleDataReader
                drd = cmd.ExecuteReader()
                If drd.Read() Then
                TextBox1.Text = drd("REGNO")
                TextBox2.Text = drd("NAME")
                 MsgBox("Data are Already exsist")
                Else
                    Dim cmd1 As New OracleCommand
                    cmd1.Connection = conn
                    cmd1.CommandText = "UPDATE REG_DETAILS SET REGNO='" & TextBox1.Text & "' AND NAME='" & TextBox2.Text & "'"
                    cmd1.CommandType = CommandType.Text
                    cmd1.ExecuteNonQuery()
                    MsgBox("Record is Successfully Edited")
                End If
            End Using
        End If
    End Sub


Remove Data from Database Table

Remove Data from Database Table:

Imports System.Data
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If (TextBox1.Text = "") Then
            MsgBox("Please Type RegNo")
       ElseIf (TextBox2.Text = "") Then
            MsgBox("Please Type Name")
       Else
            Using conn = root.Opencon()
                Dim cmd As New OracleCommand
                cmd.Connection = conn
                cmd.CommandText = "SELECT * FROM REG_DETAILS WHERE REGNO='" & TextBox1.Text & "' AND NAME='" & TextBox2.Text & "'"
               cmd.CommandType = CommandType.Text
            Dim drd As OracleDataReader
            drd = cmd.ExecuteReader()
            If drd.Read() Then
                TextBox1.Text = drd("REGNO")
                TextBox2.Text = drd("NAME")
                    If Dialog3.ShowDialog() = Windows.Forms.DialogResult.OK Then
                        Dim cmd1 As New OracleCommand
                        cmd1.Connection = conn
                        cmd1.CommandText = "delete from reg_details where REGNO='" & TextBox1.Text & "' AND NAME='" & TextBox2.Text & "'"
                        cmd1.CommandType = CommandType.Text
                        cmd1.ExecuteNonQuery()
                        MsgBox("Record is successfully deleted")
                    ElseIf Dialog3.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
                        Dialog3.Close()
                    End If
                Else
                    MsgBox("Please Type Correct Data to Delete")
                End If
            End Using
         End If
    End Sub


Connection String in Public Function

Connection String in Public Function:

Imports System.Data
Imports Oracle.DataAccess.Client 
Imports Oracle.DataAccess.Types


Public Function Opencon() As OracleConnection
        Dim oradb As String = "Data Source=XE;User Id=HR;Password=password;"
        Dim conn As New OracleConnection(oradb)
        conn.Open()
        Return conn
        conn.Close()
 End Function


Using this function:

 Using conn = Opencon()
...............code......
 End Using