コード例 #1
0
 public void EditContributor(Contributor c)
 {
     using (SqlConnection connection = new SqlConnection(_conStr))
         using (SqlCommand command = connection.CreateCommand())
         {
             command.CommandText = "UPDATE Contributors SET FirstName = @firstName , LastName = @lastName," +
                                   " CellNumber = @cellNumber, DateCreated = @date, AlwaysInclude = @alwaysInclude WHERE Id = @id";
             command.Parameters.AddWithValue("@id", c.Id);
             command.Parameters.AddWithValue("@firstName", c.FirstName);
             command.Parameters.AddWithValue("@lastName", c.LastName);
             command.Parameters.AddWithValue("@cellNumber", c.CellNumber);
             command.Parameters.AddWithValue("@date", c.DateCreated);
             command.Parameters.AddWithValue("@alwaysInclude", c.AlwaysInclude);
             connection.Open();
             command.ExecuteNonQuery();
         }
 }
コード例 #2
0
        public int AddContributor(Contributor c)
        {
            int id = 0;

            using (SqlConnection connection = new SqlConnection(_conStr))
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "INSERT INTO Contributors (FirstName, LastName, CellNumber, DateCreated, AlwaysInclude) "
                                          + " VALUES (@firstName, @lastName, @cellNumber, @date, @alwaysInclude)";
                    command.Parameters.AddWithValue("@firstName", c.FirstName);
                    command.Parameters.AddWithValue("@lastName", c.LastName);
                    command.Parameters.AddWithValue("@cellNumber", c.CellNumber);
                    command.Parameters.AddWithValue("@date", c.DateCreated);
                    command.Parameters.AddWithValue("@alwaysInclude", c.AlwaysInclude);
                    connection.Open();
                    command.CommandText += " SELECT @@IDENTITY";
                    id = (int)(decimal)command.ExecuteScalar();
                }
            return(id);
        }
コード例 #3
0
        public Contributor GetContributor(int id)
        {
            Contributor c = new Contributor();

            using (SqlConnection connection = new SqlConnection(_conStr))
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM Contributors WHERE Id = @id";
                    command.Parameters.AddWithValue("@id", id);
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    reader.Read();
                    c.Id            = (int)reader["Id"];
                    c.FirstName     = (string)reader["FirstName"];
                    c.LastName      = (string)reader["LastName"];
                    c.CellNumber    = (string)reader["CellNumber"];
                    c.DateCreated   = (DateTime)reader["DateCreated"];
                    c.AlwaysInclude = (bool)reader["AlwaysInclude"];
                }
            return(c);
        }
コード例 #4
0
        public List <Contributor> GetContributors()
        {
            List <Contributor> result = new List <Contributor>();

            using (SqlConnection connection = new SqlConnection(_conStr))
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM Contributors";
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        Contributor c = new Contributor();
                        c.Id            = (int)reader["Id"];
                        c.FirstName     = (string)reader["FirstName"];
                        c.LastName      = (string)reader["LastName"];
                        c.CellNumber    = (string)reader["CellNumber"];
                        c.DateCreated   = (DateTime)reader["DateCreated"];
                        c.AlwaysInclude = (bool)reader["AlwaysInclude"];
                        result.Add(c);
                    }
                }
            return(result);
        }