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?
Get the Number of Rows Affected Using the execute() Method The execute() method executes the given SQL query, which may return multiple results.
int a=NewCmd. ExecuteNonQuery(); if(a==0) //Not updated. else //Updated. ExecuteNonQuery() -> This function return integer value.
Although the ExecuteNonQuery returns no rows, any output parameters or return values mapped to parameters are populated with data. For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.
ExecuteNonQuery
- returns the number of rows affected.
SqlCommand comm; // other codes int numberOfRecords = comm.ExecuteNonQuery();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With