Stored Procedure to Update all tables

Posted on 2011-04-21
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 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());
      @Id int,
      @Status nvarchar(50)
Update NT1 set Status = 'Assigned' where  Id = @Id
Update NT2 set Status = 'Assigned' where  Id = @Id

Open in new window

Question by:TonyReba
    LVL 30

    Assisted Solution

    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());

    LVL 9

    Accepted Solution

    I founf the solution, actually I did not needed any parameter since I am updating the whole column...

    LVL 9

    Author Closing Comment

    Found my solution

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
    Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now