using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.Web.Configuration;

public partial class SQLParametros : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Regex.IsMatch(txtCategoria.Text, @"^[0-9a-zA-Z_\s\.\-]{1,15}$") &&
            Regex.IsMatch(txtId.Text, @"^[0-9]{1,2}$"))
        {
            ConnectionStringSettings getString = WebConfigurationManager.ConnectionStrings["nwind"] as ConnectionStringSettings;
            if (getString != null)
            {
                string sSql = "SELECT CategoryID, CategoryName FROM Categories WHERE Categories.CategoryName=@categoria and Categories.CategoryID like @id";

                using (SqlConnection conn = new SqlConnection(getString.ConnectionString))
                {
                    SqlCommand cmd = new SqlCommand(sSql, conn);
                    SqlParameter param;
                    param = cmd.Parameters.Add(new SqlParameter("@categoria", SqlDbType.VarChar, 15));
                    param.Value = txtCategoria.Text;
                    param = cmd.Parameters.Add(new SqlParameter("@id", SqlDbType.Int));
                    param.Value = txtId.Text;
                    conn.Open();

                    SqlDataReader r = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    if (r.HasRows)
                    {
                        Response.Write("Verificação OK.");
                    }
                    else
                    {
                        Response.Write("Nenhum registro retornado.");
                    }
                    r.Close();
                }
            }
        }
    }
}