Stored Procedure to Update all tables

I have several tables on my database , each table has a Id, and a status column, I want to call a stored procedure in a click event of an asp.net button .

How would I do this?


protected void Button33_Click(object sender, EventArgs e)

    {
        using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["appdevConnectionString7"].ConnectionString))
   
       
   {
      using (SqlCommand command = new SqlCommand("sp_ClearStatus", connection))
     {
      command.CommandType = CommandType.StoredProcedure;
     //     command.Transaction.
    //   command.Parameters.AddWithValue("@Id", txName.Text.Trim());
    //   command.Parameters.AddWithValue("@Status", txtDescription.Text.Trim());
      connection.Open();
      command.ExecuteNonQuery();
    }
  }
ALTER PROCEDURE sp_ClearStatus
(
      @Id int,
      @Status nvarchar(50)
)
AS
Update NT1 set Status = 'Assigned' where  Id = @Id
Update NT2 set Status = 'Assigned' where  Id = @Id

Open in new window

LVL 9
TonyRebaAsked:
Who is Participating?
 
TonyRebaConnect With a Mentor Author Commented:
I founf the solution, actually I did not needed any parameter since I am updating the whole column...

0
 
MlandaTConnect With a Mentor Commented:
your code looks correct... only thing i see is that you commented out adding the parameters. try this:

     //     command.Transaction.
    command.Parameters.AddWithValue("@Id", txName.Text.Trim());
    command.Parameters.AddWithValue("@Status", txtDescription.Text.Trim());

0
 
TonyRebaAuthor Commented:
Found my solution
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.