Obtaining DataReader schema information

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

If you are using the AseDataReader, 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”.

StepsObtaining information about a result set using the GetSchemaTable method

  1. Declare and initialize a connection object:

    For C#:

    AseConnection conn = new AseConnection(
       c_connStr );
    

    For Visual Basic .NET:

    Dim conn As New AseConnection( _
       c_connStr )
    
  2. Open the connection:

    For C#:

    conn.Open();
    

    For Visual Basic .NET:

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

    For C#:

    AseCommand cmd = new AseCommand(
       "SELECT * FROM authors", conn );
    

    For Visual Basic .NET:

    Dim cmd As New AseCommand( _
       "SELECT * FROM authors", conn )
    
  4. Create an AseDataReader object and execute the Command object you created:

    For C#:

    AseDataReader dr = cmd.ExecuteReader();
    

    For Visual Basic .NET:

    Dim dr As AseDataReader = cmd.ExecuteReader()
    
  5. Fill the DataTable with the schema from the data source:

    For C#:

    DataTable
    schema = dr.GetSchemaTable();
    

    For Visual Basic .NET:

    Dim schema As DataTable = _
       dr.GetSchemaTable()
    
  6. Close the AseDataReader and AseConnection objects:

    For C#:

    dr.Close();
    conn.Close();
    

    For Visual Basic .NET

    dr.Close()
    conn.Close()
    
  7. Bind the DataTable to the grid on the window:

    For C#:

    dataGrid.DataSource = schema;
    

    For Visual Basic .NET:

    dataGrid.DataSource = schema