I'm trying to filter records using a stored process and when I start entering the title of the record in the textbox I get an error.
Alamacenado procedure
CREATE PROCEDURE filtrar_articulo
@filtro varchar(45)
AS
BEGIN
SELECT titulo, palabras_claves, correo_elec, localizacion, tipo from Articulos
WHERE Titulo like @filtro + '%'
END
GO
Inquiry Class
public void filter(DataGridView data, string buscarTitulo)
{
try
{
string Conexion = @"string de conexion";
SqlConnection dataConnection = new SqlConnection(Conexion);
SqlCommand sql = new SqlCommand("filtrar_articulos", dataConnection);
sql.CommandType = CommandType.StoredProcedure;
sql.Parameters.Add("@filtro",SqlDbType.VarChar, 45).Value= buscarTitulo;
sql.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(sql);
da.Fill(dt);
data.DataSource = dt;
}
catch(Exception ex)
{
MessageBox.Show("Los datos no se pudieron cargar: "+ex.ToString());
}
}