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 867867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:02:43+00:00 2026-05-15T10:02:43+00:00

How to know whether a sql Update statement executed successfully or failed ? I

  • 0

How to know whether a sql Update statement executed successfully or failed ?

I use sql server 2005 and C# asp.net.

Can I get the successful or failed infomation in C# without adding some sql code into the old sql statement?

  • 1 1 Answer
  • 2 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-05-15T10:02:43+00:00Added an answer on May 15, 2026 at 10:02 am

    You can use the return value of the ExecuteNonQuery to check if the update was successful or not.

    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("sp_updateData", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter p1 = new SqlParameter("@id", SqlDbType.Int);
            p1.Value = 1;
            p1.Direction = ParameterDirection.Input;
    
            SqlParameter p2 = new SqlParameter("@name", SqlDbType.VarChar,50);
            p2.Value = "sls";
            p2.Direction = ParameterDirection.Input;
    
            cmd.Parameters.Add(p1);
            cmd.Parameters.Add(p2);
    
            try
            {
                con.Open();
                //count will be the number of rows updated. will be zero if no rows updated.
                int count = cmd.ExecuteNonQuery();
                if (count > 0)
                {
                    Console.WriteLine("Update Success!!!");
                }
                else
                {
                    Console.WriteLine("No Updates!!!");
                }
                Console.ReadLine();
    
            }
            catch (SqlException ex)
            {
                Console.WriteLine("Update Failed coz.. " + ex.Message);
            }
            finally
            {
                con.Close();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cached one DataTable fetched from SQL Server 2005 through C# ASP .NET 4.0
I know that most sql server software allows you to do A Update on
I have a Windows .net application using SQL Server 2005 Express as database, which
I would like to know whether it is possible to use a SELECT statement
I'd like to know whether there's an operator I could use in PL/SQL so
i have multiple users connecting to sql-server-2008 database. i would like to know whether
So I want to know whether transaction based web applications can have no sql
Does anyone know whether if its possible to insert binary data into an SQL
Does anyone know whether SQLServer 2005 provide auto completion when typing stuff in?? I
I'm new to Azure, I want to know about how we can implement SQL

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.