Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 » SQL Anywhere Server - Programming » SQL Anywhere Data Access APIs » SQL Anywhere .NET Data Provider » Accessing and manipulating data » Using the SACommand object to retrieve and manipulate data

 

Obtaining DataReader schema information

You can obtain schema information about columns in the result set.

If you are using the SADataReader, you can use the GetSchemaTable method to obtain information about the result set. The GetSchemaTable method returns the standard .NET DataTable object, which provides information about all the columns in the result set, including column properties.

For more information about the GetSchemaTable method, see GetSchemaTable method.

To obtain information about a result set using the GetSchemaTable method
  1. Declare and initialize a connection object.

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

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

    SACommand cmd = new SACommand(
        "SELECT * FROM Employees", conn );
  4. Create an SADataReader object and execute the Command object you created.

    SADataReader   dr = cmd.ExecuteReader();
  5. Fill the DataTable with the schema from the data source.

    DataTable       schema = dr.GetSchemaTable();
  6. Close the SADataReader and SAConnection objects.

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

    dataGrid.DataSource = schema;