ExecuteQuery:
Used to implement a single result set, for example:
Select
The general use of ExecuteQuery is a tool to implement a single result set
Executeupdate
Used to execute INSERT, UPDATE, or DELETE statements, as well as SQL DDL (data definition language) statements, such as CREATE table and DROP table. The effect of an INSERT, UPDATE, or DELETE statement is to modify one or more columns in 0 or more rows in a table.
The return value of Executeupdate is an integer that indicates the number of rows affected (that is, the update count). For statements that do not manipulate rows such as CREATE table or DROP table, the return value of executeupdate is always zero.
While Addbatch () and executeupdate () are used to perform data insertions, the difference is a batch, a single insert. These two do not use together, so Addbatch () and not write the same. Addbatch () is used to cache data, cache multiple SQL statements, and then pass the ExecuteBatch () method to the database at once, greatly improving the efficiency of execution. Executeupdate () Focus on timeliness, each write a SQL statement sent to the database to save, no cache, so the frequent operation of the database is very inefficient.
It is also important to note that when you use Addbatch () to cache data, you set conditions in the loop, execute ExecuteBatch () when the loop reaches a specified number of times, send all the SQL in the cache to the database, and then perform a clear cache of Clearbatch (). Otherwise, the data is too large to appear outofmemory (low memory).
The difference between Executeupdate,executequery,executebatch