Solved

Can Prepared statemnet returns int value C#

Posted on 2006-11-20
3
786 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
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…

695 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