示例#1
0
        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();
        }
示例#2
0
 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();
         }
 }
示例#3
0
        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);
        }