public static void Delete(Articulo articulo) { IDbCommand dbCommand = SingletonConnection.Connection.CreateCommand(); dbCommand.CommandText = "DELETE FROM articulo WHERE id=@id"; DbCommandHelper.addParameter(dbCommand, "id", articulo.id); dbCommand.ExecuteNonQuery(); }
public static void Insert(Articulo articulo) { IDbCommand dbCommand = SingletonConnection.Connection.CreateCommand(); dbCommand.CommandText = "INSERT INTO articulo (nombre, precio, categoria) VALUES (@nombre, @precio, @categoria);"; DbCommandHelper.addParameter(dbCommand, "nombre", articulo.nombre); DbCommandHelper.addParameter(dbCommand, "precio", articulo.precio); DbCommandHelper.addParameter(dbCommand, "categoria", articulo.categoria_fk); dbCommand.ExecuteNonQuery(); }
public static void Update(Articulo articulo, Articulo nuevo) { IDbCommand dbCommand = SingletonConnection.Connection.CreateCommand(); dbCommand.CommandText = "UPDATE articulo SET nombre = @nombre, precio=@precio, categoria=@categoria WHERE id =@id;"; DbCommandHelper.addParameter(dbCommand, "id", articulo.id); DbCommandHelper.addParameter(dbCommand, "nombre", nuevo.nombre); DbCommandHelper.addParameter(dbCommand, "precio", nuevo.precio); DbCommandHelper.addParameter(dbCommand, "categoria", nuevo.categoria_fk); dbCommand.ExecuteNonQuery(); }
public static string IdCategoria(string nombre) { IDbCommand dbCommand = SingletonConnection.Connection.CreateCommand(); dbCommand.CommandText = "SELECT id FROM categoria WHERE nombre=@nombre"; DbCommandHelper.addParameter(dbCommand, "nombre", nombre); IDataReader datareader = dbCommand.ExecuteReader(); //while ( datareader.Read() ) //{ // lista.Add( datareader["nombre"].ToString() ); //} //return lista.ToArray(); datareader.Read(); string retorno = datareader["id"].ToString(); datareader.Close(); return(retorno); }