Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9092473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:51:13+00:00 2026-06-16T22:51:13+00:00

I am working on asp.net(c#) project with SQL SERVER 2008. I want to update

  • 0

I am working on asp.net(c#) project with SQL SERVER 2008. I want to update three tables using one query. Please suggest me how to do that. thnaks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:51:14+00:00Added an answer on June 16, 2026 at 10:51 pm

    You can’t. Update statement works for a single table. You have to write three different queries for three tables.

    You can use transaction to make sure that your update statements are atomic.

    BEGIN TRANSACTION
    
    UPDATE Table1
    Set Field1 = '1';
    Where Field = 'value';
    
    UPDATE Table2
    Set Field1= '2'
    Where Field = 'value';
    
    UPDATE Table3
    Set Field1= '3'
    Where Field = 'value';
    
    COMMIT
    

    For C# you can use SqlTransaction. An example from the same link (bit modified)

    private static void ExecuteSqlTransaction(string connectionString)
    {
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            connection.Open();
    
            SqlCommand command = connection.CreateCommand();
            SqlTransaction transaction;
    
            // Start a local transaction.
            transaction = connection.BeginTransaction("SampleTransaction");
    
            // Must assign both transaction object and connection 
            // to Command object for a pending local transaction
            command.Connection = connection;
            command.Transaction = transaction;
    
            try
            {
                command.CommandText =
                    "UPDATE Table1 Set Field1 = '1' Where Field = 'value';";
                command.ExecuteNonQuery();
                command.CommandText =
                    "UPDATE Table2 Set Field1= '2' Where Field = 'value'";
                command.ExecuteNonQuery();
    
                command.CommandText =
                    "UPDATE Table3 Set Field1= '3' Where Field = 'value'";
                command.ExecuteNonQuery();
    
                // Attempt to commit the transaction.
                transaction.Commit();
                Console.WriteLine("Both records are written to database.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Commit Exception Type: {0}", ex.GetType());
                Console.WriteLine("  Message: {0}", ex.Message);
    
                // Attempt to roll back the transaction. 
                try
                {
                    transaction.Rollback();
                }
                catch (Exception ex2)
                {
                    // This catch block will handle any errors that may have occurred 
                    // on the server that would cause the rollback to fail, such as 
                    // a closed connection.
                    Console.WriteLine("Rollback Exception Type: {0}", ex2.GetType());
                    Console.WriteLine("  Message: {0}", ex2.Message);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an ASP.NET project (C#) with SQL Server 2008. When I insert
I am working on a project in ASP.Net, and I am using SQL Server
I'm working on an ASP.NET project for a school. In one area I want
I am working on a ASP.Net project. I have SQL Server Database linked with
I'm working on a web application project using ASP.NET MVC3 and database in SQL
I'm working on ASP.Net MVC3 web-site with Entity Framework and SQL Server 2008 as
I'm working on asp.net project using VS2010 . I want to share my project
I'm currently working on an Intranet application project, using ASP.NET MVC 3. One of
The project I am currently working on involves MS SQL Server and ASP.net Web
I am working on a ASP.Net project(c#). I have SQL Server Database linked with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.