xpo-devexpress-dot-xpo-dot-session-dot-executesprocasync-x28-system-dot-threading-dot-cancellationtoken-system-dot-string-devexpress-dot-data-dot-filtering-dot-operandvalue-x29.md
This method executes a raw stored procedure. Always validate, sanitize, or parameterize externally supplied names and values to prevent unauthorized access to sensitive information.
Asynchronously executes the specified stored procedure and returns its result set.
Namespace : DevExpress.Xpo
Assembly : DevExpress.Xpo.v25.2.dll
NuGet Package : DevExpress.Xpo
public Task<SelectedData> ExecuteSprocAsync(
CancellationToken cancellationToken,
string sprocName,
params OperandValue[] parameters
)
Public Function ExecuteSprocAsync(
cancellationToken As CancellationToken,
sprocName As String,
ParamArray parameters As OperandValue()
) As Task(Of SelectedData)
| Name | Type | Description |
|---|---|---|
| cancellationToken | CancellationToken |
A CancellationToken object that delivers a cancellation notice to the running operation.
| | sprocName | String |
A String value that specifies the stored procedure’s name.
| | parameters | OperandValue[] |
An array of OperandValue objects specifying parameters to pass to the stored procedure.
|
| Type | Description |
|---|---|
| Task<SelectedData> |
A Task<TResult> that returns a SelectedData object specifying the result set returned by the specified stored procedure.
|
This method takes in or in-out parameters. The paramerers array order should match the parameters order in the stored procedure’s signature. Out parameter values are returned in a supplementary ResultSet which includes two columns - parameter names and values. In this case the procedure returns nothing but out parameter values, the first result set will be empty and the second will contain result values. In the case where the stored procedure is a function, one more ResultSet , which contains a single cell with the function result, is returned.
Below is an example of a ExecuteSprocAsync method call.
SelectedData data = await session.ExecuteSprocAsync("TestProc", new OperandValue(123), new OperandValue("abc"));
Dim data As SelectedData = Await session.ExecuteSprocAsync("TestProc", New OperandValue(123), New OperandValue("abc"))
To visualize the result set returned by the ExecuteSprocAsync method, use XPDataView. To learn how to access the resulting data, refer to How to: Access Data in SQL Query Results. For example, you can bind the GridControl control to the ExecuteSprocAsync result as follows:
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
// ...
SelectedData sprocData = await session.ExecuteSprocAsync("MySproc");
gridControl1.DataSource = new XPDataView(session.Dictionary, session.GetClassInfo(typeof(MySproc)), sprocData);
Imports DevExpress.Xpo
Imports DevExpress.Xpo.DB
' ...
Private sprocData As SelectedData = Await session.ExecuteSprocAsync("MySproc")
gridControl1.DataSource = New XPDataView(session.Dictionary, session.GetClassInfo(GetType(MySproc)), sprocData)
To learn more about executing stored procedures in XPO, refer to Stored Procedures.
Note
You can avoid an extra request that fills the parameters list and improve performance by using the ExecuteSprocParametrizedAsync(CancellationToken, String, SprocParameter[]) method instead of ExecuteSprocAsync.
See Also