SqlResult.AffectedCount Property
.NET Standard 2.x
Gets the number of rows affected by the most recent SQL operation.
Namespace: PowerScript.Bridge
Assembly: PowerScript.Bridge.dll
Syntax
public int AffectedCount { get; }
Property Value
System.String
The number of rows affected by the most recent SQL operation.
Examples
The following code example demonstrates how to use the AffectedCount
property of the SqlResult
object to get the number of rows affected by executing the SQL statement.
using System;
using PowerScript.Bridge;
namespace Appeon.ApiDoc.SqlResultExamples
{
public class AffectedCountExample
{
private readonly SchoolContext _context;
public AffectedCountExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example()
{
// Defines a SQL statement which updates the Name field in the Department table.
string sql = "UPDATE Department SET Name = @name where DepartmentID = 1";
// Defines the parameter for the SQL statement.
string name = "Department name";
// Calls ExecuteNonQuery to execute the Update statement and stores the result in the SqlResult object.
_context.SqlExecutor.ExecuteNonQuery(sql, out SqlResult sqlResult, name);
// Shows the value of AffectedCount property of SqlResult object.
Console.WriteLine($"AffectedCount = {sqlResult.AffectedCount}");
/*This code produces the following output:
AffectedCount = 1
*/
}
}
}
Applies to
.NET Standard
2.x