This is a discussion on difference between ExecuteQuery And Execute NonQuery within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi, What is the difference between ExecuteQuery And Execute NonQuery?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| executeQuery() is for command objects i.e., this method will send "select statement" to database and returns value given by the database. executeNonQuery() uses the "Insert/Update/Delete/Stored subprogram" , this method will return number of records effected by the database table
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
| |||
| While surfing through net i got the information such as "ExecuteQuery is the method which is used to return the result of the command like select Query. The Execute Non Query is used to return the Query as the statement like the update Delete Insert that returns No data." But there is no method named ExecuteQuery in Ado.net.There are four methods which can be applied on command objects, ExecureReader, ExecuteNonQuery, ExecuteScalar, and ExecuteXmlReader. If you have any proof about the exixtence of the method ExecuteQuery then sent it ti me. Even to select some data from the DB we don't need to use the ExecuteQuery or ExecuteNonQuery(). Only to updat,insert or delete data we are using ExecuteNonQuery(). Last edited by Kirubhananth : 03-24-2008 at 04:42 AM. |
| |||
| ExecuteReader expects to run a query command or a stored procedure that selects records. It expects to have one or more resultsets to return. cmd.Connection.Open(); SqlDataReader dr = cmd.ExecuteReader(); // process the resultset(s) here cmd.Connection.Close(); You access the selected records using the SqlDataReader object and use the method Read to loop through them. You move to the next resultset using the NextResults method. ExecuteNonQuery expects to run a command, or a stored procedure, that affects the state of the specified table. This means anything but a query command. You normally use this method to issue an INSERT, UPDATE, DELETE, CREATE, and SET statement. ExecuteNonQuery returns only the number of rows affected by the command execution, or –1 should this information be unavailable. It doesn't give you a chance to access any result set generated by the statement or the stored procedure. Actually, there's really nothing to prevent you from using this method for a query command, but in this case you get neither the resultset nor the number of the affected rows. cmd.Connection.Open(); nRecsAffected = cmd.ExecuteNonQuery(); cmd.Connection.Close(); // check the record(s) affected here The number of affected rows is also made available through the RecordsAffected property of the SqlCommand object. This property equals –1 in case of errors or if a query command is executed. ExecuteScalar expects to run a query command, or more likely a stored procedure, that returns data. However, this method is different from ExecuteReader in that it just makes available, as a scalar value, the first column on the first row of the selected resultset. cmd.Connection.Open(); Object o = cmd.ExecuteScalar(); cmd.Connection.Close(); // work on the scalar here The method returns the value as a boxed object. It's then up to you to unbox or cast that value to the proper, expected type. ExecuteScalar turns out to be particularly useful when you have statistical or aggregate operations to accomplish on a certain amount of data. In these and similar circumstances, there is just one value that you might want to return back to the caller. Because of its use cases, you normally use this method on more or less complex stored procedures rather than on single SQL statements. ExecuteXmlReader builds up and returns an XmlReader object after a SELECT command that exploits XML features in SQL Server 2000 has been issued. |
| |||
| ExecuteQuery from command Object we can use the ExecuteNonQuery to perform catalog operations (Insert,Delete,Update) ExecuteNonQuery does not return any rows, any output parameters or return values mapped to parameters are populated with data. executeQuery() is for command objects i.e., this method will send "select statement" to database and returns value given by the database. Moreover the executeQuery() is not used in .net but it is used in JAVA. executeNonQuery() uses the "Insert/Update/Delete/Stored subprogram" , this method will return number of records effected by the database table Thanks KiruthikaSambandam |
| |||
| executequery applies for commands and execute nonquery for insert,update and delete. |
| |||
| ExecuteQuery from command Object we can use the ExecuteNonQuery to perform catalog operations (Insert,Delete,Update) ExecuteNonQuery does not return any rows, any output parameters or return values mapped to parameters are populated with data. |
| |||
| I agree with Kirubhananth!
__________________ QA Test Management |
| |||
| In computer programming, a keyword is a word or identifier that has a particular meaning to the programming language. The meaning of keywords — and, indeed, the meaning of the notion of keyword — differs widely from language to language. In many languages, such as DECLAN, C and similar environments like C++, a keyword is a reserved word which identifies a syntactic form. Words used in control flow constructs, such as if, then, and else are keywords. In these languages, keywords cannot also be used as the names of variables or functions. Keyword Research Florida Health Insurance |
| |||
| Hello, ExecuteQuery from command Object we can use the ExecuteNonQuery to perform catalog operations (Insert,Delete,Update) ExecuteNonQuery does not return any rows, any output parameters or return values mapped to parameters are populated with data. Byee Software development company ----------------------------------------------------------------------------- Outsourcing software development |
![]() |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/asp-asp-net-programming/5454-difference-between-executequery-execute-nonquery.html | |||
| Posted By | For | Type | Date |
| DiscussWeb IT Community - Technical Support and Technology Discussions | This thread | Refback | 03-18-2008 10:10 PM |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can I execute a PHP script using command line? | sundarraja | PHP Programming | 0 | 01-28-2008 02:53 AM |
| How can I execute an ASP page WITHOUT opening a window (hidden)? | SaravananJ | HTML, CSS and Javascript Coding Techniques | 1 | 09-19-2007 12:11 AM |
| How to execute codes when TWO keys are pressed in Flash | aramesh | Flash Actionscript Programming | 1 | 08-16-2007 02:44 AM |
| How to execute an external program from java? | kingmaker | Java Programming | 1 | 07-30-2007 12:52 AM |