// Arquivo de exemplo: NextResult.aspx.cs
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;

public partial class NextResult : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ConnectionStringSettings getString = WebConfigurationManager.ConnectionStrings["nwind"] as ConnectionStringSettings;
        if (getString != null)
        {
            string sSql = "Select CategoryName from Categories;Select ProductName from Products";

            using (SqlConnection conn = new SqlConnection(getString.ConnectionString))
            {
                SqlDataReader r = null;
                SqlCommand cmd = new SqlCommand(sSql, conn);
                try
                {
                    conn.Open();
                    r = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    if (r.HasRows)
                    {
                        int categoria = r.GetOrdinal("CategoryName");
                        Response.Write("<b>Categorias</b><br/>");
                        while (r.Read())
                        {
                            Response.Write(r[categoria].ToString() + "<br/>");
                        }
                    }
                    r.NextResult();
                    if (r.HasRows)
                    {
                        int produto = r.GetOrdinal("ProductName");
                        Response.Write("<p/><b>Produtos</b></br>");
                        while (r.Read())
                        {
                            Response.Write(r[produto].ToString() + "<br/>");
                        }
                    }
                }
                catch (SqlException)
                {
                    Response.Write("Erro SQL.");
                }
                catch (InvalidOperationException)
                {
                    Response.Write("Operação inválida.");
                }
                catch (Exception ex)
                {
                    Response.Write("Erro ao executar código.");
                }
                finally
                {
                    if (r != null) r.Close();
                }
            }
        }
    }
}

