Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get affected rows on ExecuteNonQuery

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?

like image 322
Boardy Avatar asked Apr 07 '12 23:04

Boardy


People also ask

Which method returns the number of rows affected by the execution of a query?

Get the Number of Rows Affected Using the execute() Method The execute() method executes the given SQL query, which may return multiple results.

How do I know if ExecuteNonQuery is successful C#?

int a=NewCmd. ExecuteNonQuery(); if(a==0) //Not updated. else //Updated. ExecuteNonQuery() -> This function return integer value.

What does ExecuteNonQuery () method return?

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.


1 Answers

ExecuteNonQuery - returns the number of rows affected.

SqlCommand comm; // other codes int numberOfRecords = comm.ExecuteNonQuery(); 
like image 193
John Woo Avatar answered Sep 28 '22 04:09

John Woo