The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
All docs
V19.2
19.2
19.1
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Session.ExecuteNonQueryAsync(String, CancellationToken) Method

Asynchronously executes the specified SQL statement and returns the number of rows affected.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v19.2.dll

Declaration

public Task<int> ExecuteNonQueryAsync(
    string sql,
    CancellationToken cancellationToken = default(CancellationToken)
)
Public Function ExecuteNonQueryAsync(
    sql As String,
    cancellationToken As CancellationToken = Nothing
) As Task(Of Integer)
public Task<int> ExecuteNonQueryAsync(
    string sql,
    CancellationToken cancellationToken = default(CancellationToken)
)
Public Function ExecuteNonQueryAsync(
    sql As String,
    cancellationToken As CancellationToken = Nothing
) As Task(Of Integer)

Parameters

Name Type Description
sql String

A String value that specifies an SQL statement.

cancellationToken CancellationToken

A CancellationToken object that delivers a cancellation notice to the running operation.

Parameters

Name Type Description
sql String

A String value that specifies an SQL statement.

cancellationToken CancellationToken

A CancellationToken object that delivers a cancellation notice to the running operation.

Returns

Type Description
Task<Int32>

A Task that returns an Int32 value. This value demonstrates how many of rows the specified SQL statement affects.

Returns

Type Description
Task<Int32>

A Task that returns an Int32 value. This value demonstrates how many of rows the specified SQL statement affects.

Remarks

Use ExecuteNonQueryAsync to asynchronously execute SQL statements that do not produce result sets, such as UPDATE, INSERT, and DELETE statements.

The example below demonstrates how to use this method. Here, session is the Session instance.

using System.Threading;
using DevExpress.Xpo;
// ...
CancellationTokenSource cts = new CancellationTokenSource();
await UpdateOrderDetailsAsync(cts.Token);
// ...
public async Task UpdateOrderDetailsAsync(CancellationToken cancellationToken) {
    const string queryString = 
        "UPDATE [Northwind].[dbo].[Order Details] SET [Discount] = 0.15";
    int rowsAffected = await session.ExecuteNonQueryAsync(queryString, cancellationToken);
}

To learn more about executing SQL statements in XPO, refer to Direct SQL Queries.

Note

The ExecuteNonQuery method sends statements directly, so the correct statement syntax depends on a particular database server.

See Also