public void AddDeposit(Deposits deposit) { var connection = new SqlConnection(_connectionString); var cmd = connection.CreateCommand(); connection.Open(); cmd.CommandText = @"INSERT INTO Deposits (ContributorId, Amount, Date) VALUES (@contributorId, @amount, @date) SELECT SCOPE_IDENTITY()"; cmd.Parameters.AddWithValue("@firstName", deposit.ContributorId); cmd.Parameters.AddWithValue("@lastName", deposit.Amount); cmd.Parameters.AddWithValue("@date", deposit.Date); cmd.ExecuteNonQuery(); }
public void Deposit(Deposits deposit) { using (var con = new SqlConnection(_connectionString)) using (var cmd = con.CreateCommand()) { cmd.CommandText = "INSERT INTO Deposits(contributorId, amount, date) " + "VALUES(@contributorId, @amount, @date)"; cmd.Parameters.AddWithValue("@contributorId", deposit.ContributorsId); cmd.Parameters.AddWithValue("@amount", deposit.Amount); cmd.Parameters.AddWithValue("@date", deposit.Date); con.Open(); cmd.ExecuteNonQuery(); } }
public IEnumerable <Deposits> GetDepositsById(int contribId) { var deposits = new List <Deposits>(); var connection = new SqlConnection(_connectionString); var cmd = connection.CreateCommand(); connection.Open(); cmd.CommandText = "SELECT * FROM Deposits WHERE ContributorId = @id"; cmd.Parameters.AddWithValue("@id", contribId); var reader = cmd.ExecuteReader(); while (reader.Read()) { var deposit = new Deposits(); deposit.Id = (int)reader["Id"]; deposit.Amount = (int)reader["Amount"]; deposit.Date = (DateTime)reader["Date"]; deposits.Add(deposit); } return(deposits); }