public void Update(double sum, int id) { IDbConnection con = DBUtils.getConnection(); using (var comm = con.CreateCommand()) { comm.CommandText = "update Cases set TotalSum=@sum where Id=@id"; IDbDataParameter paramSum = comm.CreateParameter(); paramSum.ParameterName = "@sum"; paramSum.Value = sum; comm.Parameters.Add(paramSum); IDbDataParameter paramId = comm.CreateParameter(); paramId.ParameterName = "@id"; paramId.Value = id; comm.Parameters.Add(paramId); var dataR = comm.ExecuteNonQuery(); if (dataR == 0) { throw new RepositoryException("No case updated!"); } } }
public IEnumerable <Case> FindAll() { IDbConnection con = DBUtils.getConnection(); IList <Case> cases = new List <Case>(); using (var comm = con.CreateCommand()) { comm.CommandText = "select * from Cases"; using (var dataR = comm.ExecuteReader()) { while (dataR.Read()) { int idV = dataR.GetInt32(0); String name = dataR.GetString(1); double totalSum = dataR.GetDouble(2); Case caz = new Case(idV, name, totalSum); cases.Add(caz); } } } return(cases); }