JT_SIRO
asked on
How can I see all recs that were affected in SQL Update Statement
In my ASP.NET app, I have a function that allows users to update the status of certain records. After the Update, I want to populate a gridview that shows the user all of the records that were updated. What's a good way to do that based off my current Update code (below). Thanks -
string strSql = "Update metadata set Status = 'Active' where Status = 'XL_Import'";
try
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = strSql.ToString();
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
string errorMsg = "Error in Updation";
errorMsg += ex.Message;
throw new Exception(errorMsg);
}
finally
{
con.Close();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The @@RowCount works only if you issue it immediately afterwards. So if you are trapping errors, you have to do it on the same line. If you split it up, you will miss out on whichever one you put second.
SELECT @NumRowsChanged = @@ROWCOUNT
Write Stored procedure for this. hope this will work.
Thanks