Execute a SQL query using ADO.NET Accelerator

Now you are ready to execute the SQL query that you have created. You will use the DbManager class included in ADO.NET Accelerator to execute your SQL queries. To execute SQL queries using the ADO.NET Accelerator you only need to use the DbManager class.

Executing a SQL query using the DbManager class in an ASP.NET web application

  1. Create a new webform.
  2. Add a Datagrid control to your webform.

    <asp:DataGrid ID="DataGrid1" runat="server">

    </asp:DataGrid>

  3. Copy the code below and paste it in the Load event of your webform. You need to put the code in the code-behind file associated to your webform.

    //For C#

    protected void Page_Load(object sender, EventArgs e)

    {

        this.DataGrid1.DataSource = SqlNetFramework.Management.DbManager.Instance.ExecuteReader(0, "DemoDb");

        this.DataGrid1.DataBind();

    }


    'For VB.NET

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Me.DataGrid1.DataSource = SqlNetFramework.Management.DbManager.Instance.ExecuteReader(0, "DemoDb")

        Me.DataGrid1.DataBind()

    End Sub

  4. Run your ASP.NET web application. The customers information must be displayed in the DataGrid.

Executing a SQL query using the DbManager class in a Windows Forms application

For VS 2002

  1. Create a new Windows Form and add a DataGrid control to your Windows Form.
  2. Copy the code below and paste it in the Load event of the Windows Form.

    //For C#

    private void Form1_Load(object sender, System.EventArgs e)

    {

        this.dataGrid1.SetDataBinding(SqlNetFramework.Management.DbManager.Instance.CreateDataSet(0, "DemoDb").Tables[0], string.Empty);

    }


    'For VB.NET

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.dataGrid1.SetDataBinding(SqlNetFramework.Management.DbManager.Instance.CreateDataSet(0, "DemoDb").Tables(0), String.Empty)

    End Sub

  3. Run your Windows Forms project. The customers information must be displayed in the DataGrid.

For VS 2005

  1. Create a new Windows Form and add a DataGridView control and a BindingSource component to your Windows Form.
  2. Copy the code below and paste it in the Load event of the Windows Form.

    //For C#

    private void Form1_Load(object sender, EventArgs e)

    {

        this.dataGridView1.DataSource = this.bindingSource1;

        this.bindingSource1.DataSource = SqlNetFramework.Management.DbManager.Instance.ExecuteReader(0, "DemoDb");

    }


    'For VB.NET

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.dataGridView1.DataSource = Me.bindingSource1

        Me.bindingSource1.DataSource = SqlNetFramework.Management.DbManager.Instance.ExecuteReader(0, "DemoDb")

    End Sub

  3. Run your Windows Forms application. The customers information must be displayed in the DataGridView.