コード例 #1
0
        public Boolean create_testimonial(Testimonial testimonial)
        {
            SqlConnection conn    = new SqlConnection();
            Boolean       success = false;

            //DateTime time = ;
            try
            {
                conn = new SqlConnection();
                string connstr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString();
                conn.ConnectionString = connstr;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection  = conn;
                comm.CommandText = "insert into [Testimonials] values (@name, @quote, @id, @course, @title)";
                comm.Parameters.AddWithValue("@name", testimonial.getStaffName());
                comm.Parameters.AddWithValue("@quote", testimonial.getQuote());
                comm.Parameters.AddWithValue("@id", testimonial.getUser().getUserID());
                //comm.Parameters.AddWithValue("@date", DateTime.Now);
                comm.Parameters.AddWithValue("@course", testimonial.getCourse_elearn().getCourseID());
                comm.Parameters.AddWithValue("@title", testimonial.getTitle());
                //comm.Parameters.AddWithValue("@content", course.getCourseID());
                int rowsAffected = comm.ExecuteNonQuery();
                success = true;
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(success);
        }