Obtaining SADataAdapter schema information

When using the SADataAdapter, you can use the FillSchema method to obtain schema information about the result set in the DataSet. The FillSchema method returns the standard .NET DataTable object, which provides the names of all the columns in the result set.

To obtain DataSet schema information using the FillSchema method

  1. Declare and initialize an SAConnection object.

    SAConnection   conn = new SAConnection(
        c_connStr );
  2. Open the connection.

    conn.Open();
  3. Create an SADataAdapter with the SELECT statement you want to use. The schema is returned for the result set of this query.

    SADataAdapter  adapter = new SADataAdapter(
        "SELECT * FROM Employees", conn );
  4. Create a new DataTable object, in this case called Table, to fill with the schema.

    DataTable       dataTable = new DataTable(
        "Table" );
  5. Fill the DataTable with the schema from the data source.

    adapter.FillSchema( dataTable, SchemaType.Source );
  6. Close the SAConnection object.

    conn.Close();
  7. Bind the DataSet to the grid on the screen.

    dataGrid.DataSource = dataTable;