Solved

Can Prepared statemnet returns int value C#

Posted on 2006-11-20
3
747 Views
Last Modified: 2012-06-27
Hi,

When we update the record in the database using prepared statement with the below code.

command.Prepare();
            command.ExecuteNonQuery();

Can we get some integer or some other value in string or int.

like

int status = command.ExecuteNonQuery();

Is this Ok or there is some other way to do this using prepared satement

Thanks in Advance
0
Comment
Question by:dinesh_bali
  • 2
3 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 17984291
By definition, it returns the number of rows effected.  Combine with a try/catch to handle errors.

int numrows=0;
try {
     numrows=cmd.ExecuteNonQuery();
    }
catch (Exception uhoh)
         {
         // oops
         }
     
0
 
LVL 3

Accepted Solution

by:
seazium earned 250 total points
ID: 17984873
ya ..,
command.ExecuteNonQuery();   ----> returns the integer value

int r_count = command.ExecuteNonQuery();  // will be OK

and also.., MSDN defines this as  ;
http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery.aspx


0
 
LVL 22

Expert Comment

by:cookre
ID: 17989236
Don't forget the try/catch
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

19 Experts available now in Live!

Get 1:1 Help Now