Issuing a Command that Returns an XmlReader Object

Issue a command that returns an XmlReader Object.

  1. Declare and initialize a Connection object:

    For C#:

    AseConnection conn = new AseConnection(connStr);
    For Visual Basic .NET:
    Dim conn As New AseConnection(connStr)
  2. Open the connection:

    For C#:

    try {
       conn.Open();
    }
    catch (AseException ex)
    {
       <error handling>
    }

    For Visual Basic .NET:

    Try
       conn.Open()
    Catch ex As AseExecption
       <error handling>
    End Try
  3. Add a Command object to define and execute a SQL statement:

    For C#:

    AseCommand cmd = new AseCommand(
       "select * from authors for xml",
       conn );

    For Visual Basic .NET:

    Dim cmd As New AseCommand( _
       "select au_lname from authors for xml", _
       conn
  4. Call the ExecuteReader method to return the DataReader object:

    For C#:

    XmlReader reader = cmd.ExecuteXmlReader();

    For Visual Basic .NET:

    Dim reader as XmlReader = cmd.ExecuteXmlReader()
  5. Use the XML Result:

    For C#:

    reader.read();
    <process xml>
    For Visual Basic .NET:
    reader.read()
    <process xml>
  6. Close the DataReader and Connection objects:

    For C#:

    reader.Close();
    conn.Close();

    For Visual Basic .NET:

    reader.close()
    conn.close()