> For the complete documentation index, see [llms.txt](https://docs.wisej.com/ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wisej.com/ai/components/api/smartadapter/wisej.ai.adapters.smartqueryadapter.md).

# SmartQueryAdapter

Namespace: **Wisej.AI.Adapters**

Assembly: **Wisej.AI** (3.5.0.0)

* [SmartAdapter](/ai/components/api/smartadapter.md)
  * [SmartQueryAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartqueryadapter.md)

Represents an adapter that generates a data set from a database schema and a user-provided description.

{% tabs %}
{% tab title="C#" %}

```csharp
public class SmartQueryAdapter : SmartAdapter
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class SmartQueryAdapter
    Inherits SmartAdapter
```

{% endtab %}
{% endtabs %}

The [SmartQueryAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartqueryadapter.md) class is designed to interact with a database schema and generate SQL queries based on user input. It utilizes a [SmartPrompt](/ai/components/api/smartprompt.md) to facilitate the query generation process.

## Constructors

### ![](/files/ptrKjmmRoQB76pvrIqh0) SmartQueryAdapter()

Initializes a new instance of the [SmartQueryAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartqueryadapter.md) class.

## Properties

### ![](/files/ptrKjmmRoQB76pvrIqh0) Connection

[IDbConnection](https://docs.microsoft.com/dotnet/api/system.data.idbconnection): Gets or sets the database connection used to execute the query.

### ![](/files/ptrKjmmRoQB76pvrIqh0) DataSource

[BindingSource](https://docs.wisej.com/api?q=wisej.web.bindingsource): Gets or sets the data source binding for the query results.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Query

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the query description provided by the user.

When the [AutoRun](/ai/components/api/smartadapter.md#autorun) property is set to true, setting this property will automatically execute the query asynchronously.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Schema

[DataTable](https://docs.microsoft.com/dotnet/api/system.data.datatable): Gets or sets the database schema used to generate the query.

### ![](/files/ptrKjmmRoQB76pvrIqh0) ServerType

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the type of the database server. (Default: `"Microsoft Sql Server"`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) SQL

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets the SQL statement generated from the query description.

## Methods

### ![](/files/KL0Ik37djZRr8a07Wopd) GetSQL(message)

Returns the JSON string returned in the *message* by stripping the enclosing markers (`sql and` ) if present.

| Parameter   | Type                                                                        | Description                                               |
| ----------- | --------------------------------------------------------------------------- | --------------------------------------------------------- |
| **message** | [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md) | Message with the response text that may be a JSON string. |

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). JSON string.

### ![](/files/KL0Ik37djZRr8a07Wopd) RunAsyncCore(control)

Asynchronously runs the core logic to generate and execute the SQL query.

| Parameter   | Type                                                      | Description                                        |
| ----------- | --------------------------------------------------------- | -------------------------------------------------- |
| **control** | [Control](https://docs.wisej.com/api?q=wisej.web.control) | The control associated with the operation, if any. |

**Returns:** [Task\<Message>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation, with a [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md) result containing the query execution details.

## Implements

| Name                                                                              | Description                                |
| --------------------------------------------------------------------------------- | ------------------------------------------ |
| [IToolProvider](/ai/components/api/smarttool/wisej.ai.smarttool.itoolprovider.md) | Represents a provider that supplies tools. |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.wisej.com/ai/components/api/smartadapter/wisej.ai.adapters.smartqueryadapter.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
