VK LABELS

Saturday, 15 March 2014

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


No comments:

Post a Comment