After the update operation is completed in the stored procedure, @ rowcount is used to return the number of affected rows. If multiple statements exist, you can define the number of rows affected by variable storage. Example:
Alter procedure [DBO]. [p_csm_updatehandleresultempname] @ handleindex Int =-1 asbegin -- set nocount on added to prevent extra result sets from -- interfering with select statements. set nocount on; update a set. fromempname = B. empname from handleresult a left join users B on. fromusername = B. openid where. handleindex> @ handleindex and. fromempname is null and B. empname is not null select @ rowcount -- This returns the number of affected rows end
Then in the C # code, use sqlcommand. executescalar () to execute the stored procedure, you can get @ rowcount, that is, the number of affected rows.
The Code is as follows:
Private int updatehandleresultempname () {sqlconnection con = new sqlconnection ("your database connection string"); sqlcommand COM = con. createcommand (); COM. commandtype = commandtype. storedprocedure; COM. commandtext = "p_csm_updatehandleresultempname"; // The Name Of The Stored Procedure con. open (); int rowcount = convert. toint32 (COM. executescalar (); con. close (); Return rowcount ;}