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

public partial class ExecuteNonQuery : System.Web.UI.Page
{
    protected void btnOK_Click(object sender, EventArgs e)
    {
        ConnectionStringSettings getString = WebConfigurationManager.ConnectionStrings["nwind"] as ConnectionStringSettings;
        if (getString != null)
        {
            string sSql = "insert into Categories(CategoryName, Description) values('Higiene', 'Produtos de limpeza em geral')";
            using (SqlConnection conn = new SqlConnection(getString.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand(sSql, conn);
                try
                {
                    conn.Open();
                    
                    int i = cmd.ExecuteNonQuery();

                    if (i > 0)
                    {
                        Label1.Text = "Registro inserido com sucesso.";
                    }
                    else
                    {
                        Label1.Text = "Erro ao inserir registro.";
                    }
                }
                catch (SqlException)
                {
                    Label1.Text = "Erro SQL.";
                }
                catch (InvalidOperationException)
                {
                    Label1.Text = "Operação inválida.";
                }
                catch (Exception)
                {
                    Label1.Text = "Erro ao executar código.";
                }
            }
        }
    }
}

