//Método BuscarNombre public DataTable Search(DCategory Category) { DataTable DtResultado = new DataTable("categoria"); SqlConnection SqlCon = new SqlConnection(); try { SqlCon.ConnectionString = Connection.Cn; SqlCommand SqlCmd = new SqlCommand(); SqlCmd.Connection = SqlCon; SqlCmd.CommandText = "buscar_categoria"; SqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter ParTextSearch = new SqlParameter(); ParTextSearch.ParameterName = "@textobuscar"; ParTextSearch.SqlDbType = SqlDbType.VarChar; ParTextSearch.Size = 100; ParTextSearch.Value = Category.TextSearch; SqlCmd.Parameters.Add(ParTextSearch); SqlDataAdapter SqlDat = new SqlDataAdapter(SqlCmd); SqlDat.Fill(DtResultado); } catch (Exception ex) { DtResultado = null; } return(DtResultado); }
//Método Insertar public string Insert(DCategory Category) { string rpta = ""; SqlConnection SqlCon = new SqlConnection(); try { //Código SqlCon.ConnectionString = Connection.Cn; SqlCon.Open(); //Establecer el Comando SqlCommand SqlCmd = new SqlCommand(); SqlCmd.Connection = SqlCon; SqlCmd.CommandText = "insertar_categoria"; SqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter ParIdcategory = new SqlParameter(); ParIdcategory.ParameterName = "@id_categoria"; ParIdcategory.SqlDbType = SqlDbType.Int; ParIdcategory.Direction = ParameterDirection.Output; SqlCmd.Parameters.Add(ParIdcategory); SqlParameter ParName = new SqlParameter(); ParName.ParameterName = "@nombre"; ParName.SqlDbType = SqlDbType.VarChar; ParName.Size = 100; ParName.Value = Category.Name; SqlCmd.Parameters.Add(ParName); SqlParameter ParDescription = new SqlParameter(); ParDescription.ParameterName = "@descripcion"; ParDescription.SqlDbType = SqlDbType.VarChar; ParDescription.Size = 256; ParDescription.Value = Category.Description; SqlCmd.Parameters.Add(ParDescription); //Ejecutamos nuestro comando rpta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "NO se Ingreso el Registro"; } catch (Exception ex) { rpta = ex.Message; } finally { if (SqlCon.State == ConnectionState.Open) { SqlCon.Close(); } } return(rpta); }
//Método Eliminar public string Delete(DCategory Category) { string rpta = ""; SqlConnection SqlCon = new SqlConnection(); try { //Código SqlCon.ConnectionString = Connection.Cn; SqlCon.Open(); //Establecer el Comando SqlCommand SqlCmd = new SqlCommand(); SqlCmd.Connection = SqlCon; SqlCmd.CommandText = "eliminar_categoria"; SqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter ParIdcategory = new SqlParameter(); ParIdcategory.ParameterName = "@id_categoria"; ParIdcategory.SqlDbType = SqlDbType.Int; ParIdcategory.Value = Category.Idcategory; SqlCmd.Parameters.Add(ParIdcategory); //Ejecutamos nuestro comando rpta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "NO se Elimino el Registro"; } catch (Exception ex) { rpta = ex.Message; } finally { if (SqlCon.State == ConnectionState.Open) { SqlCon.Close(); } } return(rpta); }