# IDataSource.QueryAsync Method

> IDataSource.QueryAsync method in the TX Sheet Control .NET API: Returns no more than request.Limit rows. Includes the syntax and a C# example.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Method
- **Namespace:** `TXTextControl.TXSheetControl.Data`
- **Package:** `TXTextControl.TXSheetControl.Server` (assembly `TXTextControl.TXSheetControl.Data.dll`, from the private NuGet feed or the supplied NuGet folder)
- **Path:** TX Sheet Control > API Reference > .NET API > TXTextControl.TXSheetControl.Data > IDataSource > IDataSource.QueryAsync Method
- **1180 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-data/idatasource/queryasync-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-data/idatasource/queryasync-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-data/idatasource/queryasync-method/llms-full.txt

---

Returns no more than request.Limit rows. Cancellation must cover opening, reading and disposal.

### Syntax

```csharp
public Task<DataSnapshot> QueryAsync(DataRequest request, CancellationToken cancellationToken = default)
```

### Parameters

| Parameter | Type | Optional | Description |
|---|---|---|---|
| `request` | `DataRequest` | No | Value matching request's declared type and the owning object's validation rules. |
| `cancellationToken` | `CancellationToken` | Yes | Cancels waiting or execution as supported by this operation. |

### Return Value

`Task<DataSnapshot>`.

### Examples

Request a bounded snapshot from an application-provided data source, honor its paging capability and write the returned columns and rows into a report.

```csharp
using TXTextControl.TXSheetControl.Data;
using TXTextControl.TXSheetControl.Server;

async Task<byte[]> ExportProviderDataAsync(ServerSheetControl control, IDataSource source)
{
    var book = control.Workbook;
    var sheet = await book.Sheets.AtAsync(0);
    var request = new DataRequest { Limit = 100 };

    if (!source.Capabilities.HasFlag(DataSourceCapabilities.Paging)) request = new DataRequest();

    var data = await source.QueryAsync(request);

    if (data.Rows.Count == 0) return await control.SaveAsync(StreamType.PDF);

    var lastColumn = "";

    for (var index = data.Columns.Count; index > 0; index /= 26) { index--; lastColumn = (char)(65 + index % 26) + lastColumn; }

    await sheet.Range("A1:" + lastColumn + "1").SetValuesAsync([data.Columns.Cast<object?>().ToArray()]);
    await sheet.Range("A2:" + lastColumn + (data.Rows.Count + 1)).SetValuesAsync(data.Rows.Select(row => row.ToArray()).ToArray());
    return await control.SaveAsync(StreamType.PDF);
}
```

### Remarks

Use the member with an instance or settings object from the documented package. Await task-returning operations. Document-bound handles must be resolved again after loading or deleting their owner.

### See Also

- [IDataSource Interface](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-data/idatasource/llms-full.txt)
- [Workbooks and Worksheets](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/workbooks/llms-full.txt)
- [DataRequest Class](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-data/datarequest/llms-full.txt)
- [DataSnapshot Class](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-data/datasnapshot/llms-full.txt)

---

## Nearby

- **Previous:** [IDataSource.Capabilities Property](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-data/idatasource/capabilities-property/llms-full.txt)
- **Next:** [WorkbookDataBinding Class](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-data/workbookdatabinding/llms-full.txt)
