Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 790
  • Last Modified:

Can Prepared statemnet returns int value C#

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
dinesh_bali
Asked:
dinesh_bali
  • 2
1 Solution
 
cookreCommented:
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
 
seaziumCommented:
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
 
cookreCommented:
Don't forget the try/catch
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now