Issuing a Command that Returns a Complete Result Set

Issue a command that returns a complete result set.

  1. Declare and initialize a Connection object:

    For C#:

    AseConnection conn = new AseConnection(connStr);

    For Visual Basic .NET:

    Dim conn As New AseConnection(connStr)

    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
  2. Add a Command object to define and execute a SQL statement:

    For C#:

    AseCommand cmd = new AseCommand(_
              "select au_lname from authors", conn );

    For Visual Basic .NET:

    Dim cmd As New AseCommand("select au_lname from authors", conn)
    Note: When you retrieve data from the database using a stored procedure, and the stored procedure returns both an output parameter value and a result set, then the result set will be reset and you will be unable to reference result set rows as soon as the output parameter value is referenced. In these situations, Sybase recommends that you reference and exhaust all rows in the result set and leave the referencing output parameter value to the end.

    For more information, see Using Stored Procedures and AseParameter Class.

  3. Call the ExecuteReader method to return the DataReader object:

    For C#:

    AseDataReader reader = cmd.ExecuteReader();

    For Visual Basic .NET:

    Dim reader as AseDataReader = cmd.ExecuteReader()
  4. Display the results:

    For C#:

    listAuthors.BeginUpdate(); 
    while( reader.Read() ) { 
              listAuthors.Items.Add( reader.GetString( 0 ) );
    }
    listAuthors.EndUpdate();

    For Visual Basic .NET:

     listAuthors.BeginUpdate()
    While reader.Read()
       listAuthors.Items.Add(reader.GetString(0))
    End While
    listAuthors.EndUpdate()
  5. Close the DataReader and Connection objects:

    For C#:

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

    For Visual Basic .NET:

    reader.close()
    conn.close()
Related concepts
Stored Procedures
AseParameter Class