10 VB.NET Articles - How to execute a SQL Server Procedure in VB.NET
Viewing Article

Current Rating :

How to execute a SQL Server Procedure in VB.NET

Wednesday, February 09, 2011Posted by admin

Category:vb.Net Utilities
 

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 Try 'Call Open database - connect to the database OpenConnection(cn) ' I use a seperate function to open a new connection dc.ExecuteNonQuery() Catch MsgBox("Unable to Delete the record:," & Err.Description) 'Finally da.Dispose() dc.Dispose() dcB.Dispose() CloseConnection(cn) ' I use a seperate function to close an existing connection MsgBox("Record Deleted") End Try End Sub

Hits:248      Current Rating :      No Of Ratings: 644      AuthorName: admin
  

Comment#23      Friday, February 11, 2011          Posted by Sumeet Singh

 
Hi this site is really great

Comments

Your Name  
 
Your Email( will not appear on page)  
Your Comments