?
Solved

Stored Procedure to Update all tables

Posted on 2011-04-21
3
Medium Priority
?
192 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:TonyReba
  • 2
3 Comments
 
LVL 31

Assisted Solution

by:MlandaT
MlandaT earned 200 total points
ID: 35444021
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
 
LVL 9

Accepted Solution

by:
TonyReba earned 0 total points
ID: 35444084
I founf the solution, actually I did not needed any parameter since I am updating the whole column...

0
 
LVL 9

Author Closing Comment

by:TonyReba
ID: 35465263
Found my solution
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question