For Answers, see/post comments

Delete a record from the database

This function will delete the record based on your delete condition and table from which the data has to be deleted. It will return 0 or 1 based on the output.


Public Function DeleteRecords(ByVal TableName As String, ByVal DeleteAndSelectCondition As String) As Integer
Dim oCon As New OleDbConnection(mConnectionString)
Dim sSQL As String, i As Integer
sSQL = "delete from " & TableName & " where " & DeleteAndSelectCondition
Try
oCon.Open()
Dim oCmd As New OleDbCommand(sSQL, oCon)
i = oCmd.ExecuteNonQuery()
If ContextUtil.IsInTransaction = True Then ContextUtil.SetComplete()
oCon.Close()
Return i
Catch e As Exception
If ContextUtil.IsInTransaction = True Then ContextUtil.SetAbort()
Throw New Exception(e.Message & vbNewLine & e.Source & ":-DeleteRecords")
End Try
End Function

No comments: