Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the "Non" in "ExecuteNonQuery"?

Tags:

I know this is not a hell of an useful question but I can't help being bugged by it.

So,
Why said method (in *Command classes) is called
ExecuteNonQuery instead of ExecuteQuery?

Aren't those SQL statements we throw at DBs, queries?

like image 669
Camilo Martin Avatar asked May 14 '10 12:05

Camilo Martin


People also ask

Why we use execute non query?

ExecuteNonQuery: Use this operation to execute any arbitrary SQL statements in SQL Server if you do not want any result set to be returned. You can use this operation to create database objects or change data in a database by executing UPDATE, INSERT, or DELETE statements.

What is a non query?

Apr, 2016 1. ExecuteNonQuery used for executing queries that does not return any data. It is used to execute the sql statements like update, insert, delete etc. ExecuteNonQuery executes the command and returns the number of rows affected. Jan, 2018 20.

Why ExecuteNonQuery is not working?

You have to assign the connection for the command object. Your code is vulnerable to SQL injection. Also, you should use a using block with classes that implement the IDisposable interface, especially with the SqlConnection class in order to close the connection in case of an exception.

What is the difference between ExecuteScalar and ExecuteNonQuery?

Solution 1. ExecuteScalar() only returns the value from the first column of the first row of your query. ExecuteReader() returns an object that can iterate over the entire result set. ExecuteNonQuery() does not return data at all: only the number of rows affected by an insert, update, or delete.


1 Answers

Semantically, a query is something you execute to return data. You're 'querying' the database to find all the X in the Y.

If you're not expecting back results, it's not so much a query as it is a statement or command.

like image 174
Tejs Avatar answered Sep 28 '22 17:09

Tejs