Delete Data in Access Asp.Net Vb.Net



In this post Delete Data in Access Asp.Net Vb.Net

Important Namespaces Used
--------------------------

Imports System.Data.OleDb
Imports System.Data.DataSet
Imports System.Data

--------------------------

Search Button Click Event Coding
---------------------------------

Try

            Dim ds As New DataSet
            Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Server.MapPath("~/App_Data/StudentData.accdb") & "; Persist Security Info=False")
            Dim query As String = "SELECT * FROM PersonalInfo where srollno=" + TextBox1.Text
            Dim cmd = New OleDbCommand(query, con)
            Dim Da As New OleDbDataAdapter(cmd)
            Da.Fill(ds)
            Dim i = ds.Tables(0).Rows.Count()
            If (i > 0) Then
                Label3.Text = "Record Found Successfully"
                TextBox2.Text = ds.Tables(0).Rows(0)("sname").ToString()
                TextBox3.Text = ds.Tables(0).Rows(0)("fname").ToString()
                TextBox4.Text = ds.Tables(0).Rows(0)("mname").ToString()
                TextBox1.Enabled = False

            Else
                Label3.Text = "No Record Found"
            End If

            con.Close()

        Catch ex As Exception
            Label3.Text = "There is Some Problem While Saving Data" & ex.ToString()

        End Try

---------------------------------

Delete Button Click Event Coding
---------------------------------

 Try
            Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Server.MapPath("~/App_Data/StudentData.accdb") & "; Persist Security Info=False")

            Dim query As String
            query = "Delete from personalinfo where srollno=" + TextBox1.Text


            Dim cmd As New OleDbCommand(query, con)
            con.Open()
            cmd.ExecuteNonQuery()
            Label4.Text = "Data Has Been Deleted Successfully"
            con.Close()
            TextBox1.Text = ""
            TextBox1.Enabled = True
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""

        Catch ex As Exception
            Label3.Text = "There is Some Problem While Saving Data" & ex.ToString()

        End Try

0 Comment's

Comment Form

Submit Comment