Beispiel #1
0
        public void InsertContributor(Contributor contributor)
        {
            SqlConnection connection = new SqlConnection(_connectionString);
            SqlCommand    cmd        = connection.CreateCommand();

            cmd.CommandText = @"INSERT INTO Contributors VALUES (@firstName, @lastName, @cellNumber, @date, @alwaysInclude) SELECT SCOPE_IDENTITY()";
            cmd.Parameters.AddWithValue("@firstName", contributor.FirstName);
            cmd.Parameters.AddWithValue("@lastName", contributor.LastName);
            cmd.Parameters.AddWithValue("@cellNumber", contributor.CellNumber);
            cmd.Parameters.AddWithValue("@date", contributor.Date);
            cmd.Parameters.AddWithValue("@alwaysInclude", contributor.AlwaysInclude);
            connection.Open();
            contributor.Id = (int)(decimal)cmd.ExecuteScalar();
            connection.Close();
            connection.Dispose();
        }
Beispiel #2
0
        public void UpdateContributor(Contributor contributor)
        {
            SqlConnection connection = new SqlConnection(_connectionString);
            SqlCommand    cmd        = connection.CreateCommand();

            cmd.CommandText = @"UPDATE Contributors SET FirstName = @firstName, LastName = @lastName, CellNumber  = @cellNumber,
                               Date = @date, AlwaysInclude = @alwaysInclude WHERE id = @id";
            cmd.Parameters.AddWithValue("@firstName", contributor.FirstName);
            cmd.Parameters.AddWithValue("@lastName", contributor.LastName);
            cmd.Parameters.AddWithValue("@cellNumber", contributor.CellNumber);
            cmd.Parameters.AddWithValue("@date", contributor.Date);
            cmd.Parameters.AddWithValue("@alwaysInclude", contributor.AlwaysInclude);
            cmd.Parameters.AddWithValue("@id", contributor.Id);
            connection.Open();
            cmd.ExecuteNonQuery();
            connection.Close();
            connection.Dispose();
        }