Get affected rows on ExecuteNonQuery

Boardy picture Boardy · Apr 8, 2012 · Viewed 96.4k times · Source

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?

Answer

John Woo picture John Woo · Apr 8, 2012

ExecuteNonQuery - returns the number of rows affected.

SqlCommand comm;
// other codes
int numberOfRecords = comm.ExecuteNonQuery();