public void AddSimcha(Simcha s)
 {
     using (SqlConnection connection = new SqlConnection(_conStr))
         using (SqlCommand command = connection.CreateCommand())
         {
             command.CommandText = "INSERT INTO Simchas (Name, Date) VALUES (@name, @date)";
             command.Parameters.AddWithValue("@name", s.Name);
             command.Parameters.AddWithValue("@date", s.Date);
             connection.Open();
             command.ExecuteNonQuery();
         }
 }
Exemple #2
0
        public Simcha GetSimcha(int id)
        {
            Simcha simcha = new Simcha();

            using (SqlConnection connection = new SqlConnection(_conStr))
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM Simchas WHERE Id = @id";
                    command.Parameters.AddWithValue("@id", id);
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    reader.Read();
                    simcha.Id   = (int)reader["Id"];
                    simcha.Date = (DateTime)reader["Date"];
                    simcha.Name = (string)reader["Name"];
                }
            return(simcha);
        }