using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Web.UI;

public partial class storedprocedure : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ConnectionStringSettings getString = WebConfigurationManager.ConnectionStrings["nwind"] as ConnectionStringSettings;
            if (getString != null)
            {

                using (SqlConnection conn = new SqlConnection(getString.ConnectionString))
                {
                    SqlCommand cmd = new SqlCommand("Exibir", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlParameter param = cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int));
                    param.Direction = ParameterDirection.Input;
                    param.Value = 1;
                    SqlDataReader r = null;
                    try
                    {
                        conn.Open();
                        r = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                        if (r.HasRows)
                        {
                            int id = r.GetOrdinal("CategoryID");
                            int categoria = r.GetOrdinal("CategoryName");
                            while (r.Read())
                            {
                                Response.Write("Identificador: " + r[id].ToString() + "<br/>");
                                Response.Write("Categoria: " + r[categoria].ToString() + "<p/>");
                            }
                        }
                    }
                    catch (SqlException)
                    {
                        Response.Write("Erro SQL.");
                    }
                    catch (InvalidOperationException)
                    {
                        Response.Write("Operação inválida.");
                    }
                    catch (Exception)
                    {
                        Response.Write("Erro ao executar código.");
                    }
                    finally
                    {
                        if (r != null) r.Close();
                    }
                }
            }
        }

    }
}