//Método BuscarNombre public DataTable Search(DPresentations Presentations) { DataTable DtResultado = new DataTable("presentacion"); SqlConnection SqlCon = new SqlConnection(); try { SqlCon.ConnectionString = Connection.Cn; SqlCommand SqlCmd = new SqlCommand(); SqlCmd.Connection = SqlCon; SqlCmd.CommandText = "buscar_presentacion"; SqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter ParTextSearch = new SqlParameter(); ParTextSearch.ParameterName = "@textobuscar"; ParTextSearch.SqlDbType = SqlDbType.VarChar; ParTextSearch.Size = 100; ParTextSearch.Value = Presentations.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(DPresentations Presentations) { 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_presentacion"; SqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter ParIdpresentations = new SqlParameter(); ParIdpresentations.ParameterName = "@id_presentacion"; ParIdpresentations.SqlDbType = SqlDbType.Int; ParIdpresentations.Direction = ParameterDirection.Output; SqlCmd.Parameters.Add(ParIdpresentations); SqlParameter ParName = new SqlParameter(); ParName.ParameterName = "@nombre"; ParName.SqlDbType = SqlDbType.VarChar; ParName.Size = 100; ParName.Value = Presentations.Name; SqlCmd.Parameters.Add(ParName); SqlParameter ParDescription = new SqlParameter(); ParDescription.ParameterName = "@descripcion"; ParDescription.SqlDbType = SqlDbType.VarChar; ParDescription.Size = 256; ParDescription.Value = Presentations.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(DPresentations Presentations) { 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_presentacion"; SqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter ParIdpresentations = new SqlParameter(); ParIdpresentations.ParameterName = "@id_presentacion"; ParIdpresentations.SqlDbType = SqlDbType.Int; ParIdpresentations.Value = Presentations.Idpresentation; SqlCmd.Parameters.Add(ParIdpresentations); //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); }