Search Results for

    Show / Hide Table of Contents

    GetAdapter method

    The method returns a new object of type DbDataAdapter, specific to this connection. This object is used to fill the table with data.

    The following parameters are passed to the method:

    Parameter Description
    selectCommand SQL query text.
    connection Object of type DbConnection, created in the GetConnection method.
    Parameters Query parameters, if defined.

    Let's look at an example implementation of this method in MsSqlDataConnection:

    public override DbDataAdapter GetAdapter(string selectCommand, DbConnection connection,
      CommandParameterCollection parameters)
    {
      SqlDataAdapter adapter = new SqlDataAdapter(selectCommand, connection as SqlConnection);
      foreach (CommandParameter p in parameters)
      {
        SqlParameter parameter = adapter.SelectCommand.Parameters.Add(p.Name, (SqlDbType)p.DataType, p.Size);
        parameter.Value = p.Value;
      }
      return adapter;
    }
    

    The method creates an adapter specific to MS SQL, fills the query parameters and returns the adapter. The parameters should be described in more detail. The query text may contain parameters. In this case, a collection of parameters in the parameters variable is passed to the method - these are the parameters defined in the FastReport designer when the query was created. You must add the parameters to the adapter.SelectCommand.Parameters list. Each parameter in the parameters collection has the following properties:

    Property Description
    Name Parameter name.
    DataType The data type of the parameter. This is an int type property; you must cast it to the type used for the parameters in this connection.
    Size The size of the parameter data.
    Value The value of the parameter.

    Most of the time you have to override this method. It is used in two other methods, FillTableSchema and FillTableData. If your connection type doesn't use the DbConnection and DbDataAdapter objects to get information about the table and load data into it, you may not override this method. In that case, you must override the FillTableSchema and FillTableData methods.

    Back to top © 1998-2025 Copyright Fast Reports Inc.