Make General Procedure for Delete data .

This Procedure create in the module. call form any where when want to delete data from the Table. This reduce the code and time is saving.

Here call the procedure with passing Tablename and Where Condition.

Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
Dim TableName As String
Dim mWhere As String
TableName = "Employee"
mWhere = "EmpNo='0001'"
DeleteTableDataScr(TableName, mWhere)
End Sub

This is the detete procedure need to declare in the Module

Public Sub DeleteTableDataScr(ByVal tName As String, ByVal mWhere As String)
If MsgBox("Do you want to Delete (Y/N)?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
Dim cmd As New System.Data.SqlClient.SqlCommand
cmd.CommandType = System.Data.CommandType.Text
If mWhere = "" Then
cmd.CommandText = "Delete " & tName
cmd.CommandText = "Delete " & tName & " Where " & mWhere
End If
cmd.Connection = SqlConn
Exit Sub
End If


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: