?
Solved

Can Prepared statemnet returns int value C#

Posted on 2006-11-20
3
Medium Priority
?
787 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

741 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