Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I study about SQL database connection online, but I don't understand one point. It is "executenonquery();. I don't know why we have to use it

What I have tried:

I don't under why we use it in SQL database connection in c#.
Posted
Updated 15-Mar-17 1:42am
v2
Comments
[no name] 14-Mar-17 11:26am    
When you looked up "ExecuteNonQuery" in the documentation to read about what it did, what exactly was unclear about its functionality?

ExecuteQuery runs a query.
ExecuteNonQuery runs a command or an update.

See Difference between ExecuteQuery And Execute NonQuery « Code Simplified – Viral Sarvaiya[^]
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 14-Mar-17 13:27pm    
Simple as that. 5ed.
ExecuteNonQuery is used when you are not trying to retrieve data from the DB but do other actions like Create, Update, and Delete operations.
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 14-Mar-17 13:27pm    
5ed.
Probably because :
ExecuteQuery runs a command (like SELECT) that return dataset as answer.
ExecuteNonQuery runs a command (like INSERT or DELETE) that don't.
 
Share this answer
 
v3
In simple lines, for CRUD operations we use ExecuteNonQuery where we are modifying the DB. And as discussed above, for detailed explanation visit any of the above links mentioned.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900