I am currently working on a C# project and I am running an insert query which also does a select at the same time, e.g.:
INSERT INTO table (SELECT * FROM table WHERE column=date)
Is there a way I can see how many rows were inserted during this query?
If you run a bulk of ExecuteNonQuery(), and commit them all in once, you can get the number of total changes after connection by read the return value from "SELECT total_changes();"
The function to get the total changes:
Use it in another function:
ExecuteNonQuery
- returns the number of rows affected.If you run the SQL from your question in a
SqlCommand
and check the return value ofExecuteNonQuery
it should tell you how many records were affected.From the documentation:
ExecuteNonQuery return the affected rows ONLY WHEN Use Affected Rows in the connections properties is set, if not (default) returns matched rows.
Be sure of one thing also You need to add a statement in the connection string For example:
Be sure of:
so it will return a right value of rows affected