public static Televisor TraerUno(int codigo) { Televisor retorno = null; SqlConnection conexion = new SqlConnection(Televisor.conexion); SqlCommand comando = new SqlCommand(); comando.CommandText = string.Format("SELECT * FROM Televisores WHERE codigo={0}", codigo); comando.CommandType = System.Data.CommandType.Text; comando.Connection = conexion; try { conexion.Open(); SqlDataReader lector = comando.ExecuteReader(); //if(lector.HasRows) if (lector.Read()) { //lector.Read(); retorno = new Televisor(lector.GetInt32(0), lector.GetString(1), lector.GetDouble(2), lector.GetInt32(3), lector.GetString(4)); } conexion.Close(); } catch (Exception) { } return(retorno); }
public static bool Borrar(Televisor t) { bool retorno = false; SqlConnection conexion = new SqlConnection(Televisor.conexion); SqlCommand comando = new SqlCommand(); comando.CommandText = string.Format("DELETE FROM Televisores WHERE codigo={0}", t.codigo); comando.CommandType = System.Data.CommandType.Text; comando.Connection = conexion; try { conexion.Open(); comando.ExecuteNonQuery(); conexion.Close(); retorno = true; } catch (Exception) { } return(retorno); }
public static bool Modificar(Televisor t) { bool retorno = false; SqlConnection conexion = new SqlConnection(Televisor.conexion); SqlCommand comando = new SqlCommand(); comando.CommandText = string.Format("UPDATE Televisores SET marca='{0}',precio={1},pulgadas={2},pais='{3}' WHERE codigo={4}", t.marca, t.precio, t.pulgadas, t.pais, t.codigo); comando.CommandType = System.Data.CommandType.Text; comando.Connection = conexion; try { conexion.Open(); comando.ExecuteNonQuery(); conexion.Close(); retorno = true; } catch (Exception) { } return(retorno); }