.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to execute DELETE stored procedure programmatically (C#)

Posted By:      Posted Date: October 07, 2010    Points: 0   Category :ASP.Net

 I need to execute a stored procedure which is a simple delete (record) query. Programmaticaly, I want to pass in a parameter "ID1".

Assume I will pass in the ID1 parameter on a delete link click event froma GridView control. What would the code be to execute the existing stored procedure?

Also assume:

ID1 - the parameter and primary key of the source database for the record to be deleted

GridView1 - the GridView control

spDeleteRecord - the stored procedure needing the parameter ID1 and to be executed from C# code

Here's my start:

protected void GridView1_RowDeleting(object sender, EventArgs e)
TableCell cell = GridView1.Rows[e.RowIndex].Cells[1];
int ID1 = System.Convert.ToInt16(cell.Text);
??? - code here to call and execute parameter query

View Complete Post

More Related Resource Links

Execute system stored procedure

This should be very simple, but I haven't found the solution yet.  I'm writing a Q&D application to setup log shipping for a large number of databases.  I need to execute several stored procedures (e.g. sp_add_log_shipping_primary_database) which will return a value plue two output parameters that I need.  I've taken the code generated by SQL Server and executed it in a SMSS query window.  I've tried configuring an ADODB command with EXEC sp_name parm1, parm2, ..., parm 12 OUTPUT and setup parameters on the command without success (The connection cannot be used to perform this operation.).  I tried stringing all of the statements needed together in one line separated by semi-colons (executed without error but didn't return any values). I'm using VB2010 and SQL Server 2008.  Any suggestions would be appreciated.

Execute SSIS package stored in Database - From Stored Procedure

Dear frnds, I am trying to execute a SSIS package that is stored in a SQL Server 2005 database Want to execute from a stored procedure in same database.  What commands/operations are necessary ? I am also having Two parameter. Regards, sajid 

ExecuteNonQuery using stored procedure will not delete record (SQLDataAdapter)

Hi all I'm using VB.net 2.0 with a SQL server (2005) backend db. I've got a very odd problem. I'm trying to use a stored procedure with a parameter to delete a record from a table. I've tested the stored procedure by running it directly from visual studio and it works fine, but when running it through my application nothing happens. There's no error and it appears to have worked but the record is not deleted. I've checked permissions on the backend db and giving the network ASPNet account the db owner role has no effect either. Here's the code, there are 3 layers - the webform code, then the business logic class, then the dataconnection class. 'firstly the original code that is run from the webform when the user selects to delete the record Partial Public Class NewPerson     Inherits System.Web.UI.Page    Private newConn As New DBConnection    Private currentNewRequest As New NewRequest(newConn)     Protected Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click     Dim requestID As Integer = CInt(Me.lblRecordID.Text)    Me.currentNewRequest.newRequestID = requestID    Me.newConn.openConnection()    Me.currentNewRequest.DeleteRecord()    Me.newConn

With Recompile and Execute as clause in SQL 2005 Stored Procedure



I am working on an asp.net application which uses quite a few sql 2005 procedures. Due to some change in requirement I had to modify a couple of the procedures.

During this change, I found that most of the procedures contain clause With Recompile, Execute As Caller.

I am planning to refactor the code in procedure but not sure if I can remove these clauses. Can any one please help me with these?

Thanks in advance.

Can a stored procedure programmatically determine if an SSIS package is running?



If I have the 'ExecutionInstanceGUID' value for an SSIS package that I know was started, is there a way that a stored procedure can programmatically determine whether the SSIS package still is running?

Thanks -



Can a stored procedure programmatically determine the name of the SQL Agent job that executed it?



We have a SQL Agent job that runs a stored procedure.  Is it possible for the stored procedure to programmatically determine the name of the SQL Agent job that executed it?  (Without the agent job passing its name to the procedure through a parameter.)  How would you do it?

Thanks -


SQL Command Or Stored Procedure in Execute SQL Task


Hi all,

Which is a better way to do in Execute SQL Task : Direct SQL input or Create a stored proc in database and then use that.

In my opinion, Stored Procedure is a better and recommended way for following reasons:

  • Cached execution plan
  • More secure
  • Centralized code
  • Code reuse

Please let me know if this is not the case with SSIS Execute SQL Task.


Need to execute ALTER DATABASE inside stored procedure


SQL 2005 Standard.

I wrote a sp that uses ALTER DATABASE instruction. When I execute sp with elevated user it works fine; when I try to execute that sp with a normal user (I alerady gave execute permission for that user) it fails with "alter database failed".

I tried to modify create proc with execute as owner but nothing changed.

How can I do ?


GridView delete using stored procedure problem (strange)


I'm getting an error and I can't understand why is this happening...
I have an stored procedure which receives a parameter to delete the database row corresponding to that key-parameter. In the GridView_RowCommand I'm setting up the datasource in the e.CommandName == "Delete" option     

this.SqlDataSourceGridView.DeleteCommandType = SqlDataSourceCommandType.StoredProcedure;
this.SqlDataSourceGridView.DeleteCommand = "spDeleteGridView";

Then in the GridView_RowDeleting event, I'm preparing datasourceDeleteParameters with the Key that I want to delete in my database and call the         

this.SqlDataSourceGridView.Delete ( );

The row is deleted in the database but, and here is the problem, there is something that before it got error and throws me that:

El procedure or funcion 'spDeleteGridView' waits the parameter '@PARAM', that what not expected.

I must add the information that debugging GridView_RowDeleting it ends normally and calls the GridView_RowDeleted...

Any help??

Thank you!!!

How to write Stored Procedure for Insert Data & Execute it in MS SQL?


How to write Stored Procedure for Insert Data & Execute it in MS SQL?

How to execute ssis package from stored procedure

how to excute ssis package from stored procedure and get the parameters back from ssis into the stored procedure.

Getting Output value from a Stored Procedure in Execute SQL



I have an Execute SQL task ,in which I am having an stored procedure.

My requirement is I have to map the output value of sp to the output value of my Execute SQl Task.

So that once after the Execution of ExecuteSQL Task.I can have a check in precedence constraints and based on that I can move forward.

Thanks, A2H

Cannot find execute any query, stored procedure not found even if it is there


Hey guys,

I am getting frustrated with this problem, I dont know what i did, but now I cannot execute any stored procedured when I could last time.

When I use my asp.net application to run the query, it finds the stored procedure but when I execute it is sql management studio it says it cannot find the stored procedure even though it is there.

I tried to execute other procedures and the samething happens. Even when I try a simple query it says it cannot find the table

I could execute the query if i placed Use [databasename] in front, but even with this, I cannot execute stored procedures.

does any1 know how to fix this?

Ju Lian

How to execute a parameterized stored procedure using ssis dataflow script component transformation


Hi All,

Can any body send code for how to execute a parameterized stored procedure  using ssis dataflow script component transformation using .net

I know how to execute storedproc using control flow script task, but I need using ssis dataflow script component transformation.




Execute stored procedure on linked DB2 server from MS SQL 2008 SP1 64 bit problem

Hi everybody. I am trying to execute stired procedure on linked DB2 server from MS SQL 2008 x64
I installed IBM Access client x64 and on provider tab showed up 3 providers IBMDASQL,IBMDA400,IBMDARLA
I installed linked server as shown on this two links:


I installed linked server using all this 3 providers

    @srvproduct=N'DB2 UDB for iSeries',
    @provider=N'IBMDASQL',-- provider for example
    @datasrc=N'ASTEST', -- mydatasource
exec sp_addlinkedsrvlogin DB2,false,null,'telebank','password'

I can run procedure from the extended stored procedure, but when i try to execute it as shown on the linkes above i get the following error:
Could not execute statement on remote server 'DB2'.

  @branch    as varchar(4),
  @cli   as varchar(6),
  @suffix    as varchar(3),
  @date1     a

SQL Server 2005 Grant User Permission to Create Stored Procedure and Grant Execute Access to another


I'm trying to determine the minimal amount of access I can give my developers to be able to run create stored procedure scripts with an inclusion of the grant execute to the application user group.

We have been developing some interesting work arounds, but I think there must be an easier way to grant the access.

Grant Create Stored Procedure to user1 on a specific database

Grant Permission to Grant Execute permission for Stored Procedures on a specific Database to user1 for any user.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend