Search Delete records in windows

Satyapriyanayak
Posted by Satyapriyanayak under VB.NET category on | Points: 40 | Views : 587
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim ConnectionString As String = System.Configuration.ConfigurationSettings.AppSettings("dsn")
Dim com As OleDbCommand
Dim str As String
Private Sub btn_delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_delete.Click
If TextBox1.Text = "" Then
MsgBox("Please enter name")
Else
namecheck()

Try
Dim con As New OleDbConnection(ConnectionString)
str = "Delete from stpl where Mandal='" & TextBox1.Text & "'"
com = New OleDbCommand(str, con)
con.Open()
com.ExecuteNonQuery()
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
MessageBox.Show("Would you like to delete?", "Deleting Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Question)
TextBox1.Text = ""
End If
End Sub
Private Sub namecheck()
Dim con As New OleDbConnection(ConnectionString)
con.Open()
str = "select count(*)from stpl where Mandal='" + TextBox1.Text & "'"
com = New OleDbCommand(str, con)
Dim count As Integer = Convert.ToInt32(com.ExecuteScalar())
If count > 0 Then
MessageBox.Show("Record exits")
Else
MessageBox.Show("Record does not exits")
End
End If
End Sub
End Class

Comments or Responses

Login to post response