How to execute a SQL Server Procedure in VB.NET

How to execute a Backend Procedure in SQL Server using VB.NET

Here is a function which allows you to execute a SQL Server Procedure in VB.NET

Function ExecuteProcedure_DeleteRecord() as boolean

Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Dim sql As String

sql = "cs_Post_Delete"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@SectionID", "200") ' string then enclose it in the double quotes
cmd.Parameters.AddWithValue("@SettingsID", 1000) ' numeric value then you can put it without any quotes
cmd.Parameters.AddWithValue("@PostID", Me.TextBox1.Text) ' Here we are picking a value from a textbox
cmd.Parameters.AddWithValue("@ResetStatistics", 1)
cmd.Parameters.AddWithValue("@DeletedBy", 2109)
cmd.Parameters.AddWithValue("@Reason", "Deleted due to SPAM")
cmd.CommandText = sql
cmd.Connection = cn

'Call Open database - connect to the database
OpenConnection(cn) ' I use a seperate function to open a new connection

MsgBox("Unable to Delete the record:," & Err.Description)
CloseConnection(cn) ' I use a seperate function to close an existing connection
MsgBox("Record Deleted")
End Try

End Sub