protected void btnInsert_Click(object sender, EventArgs e) { try { Course newCourse = new Course(); newCourse.Name = txtNewName.Text; newCourse.Title = txtNewTitle.Text; newCourse.Credits = Convert.ToByte(txtNewCredits.Text); newCourse.Department = Convert.ToInt32(txtNewDepartment.Text); IronwoodEntities2 context = new IronwoodEntities2(); context.AddObject("Courses", newCourse); context.SaveChanges(); lblMessages.Text = "Course successfully inserted!"; txtNewCredits.Text = ""; txtNewDepartment.Text = ""; txtNewName.Text = ""; txtNewTitle.Text = ""; } catch (Exception ex) { lblMessages.Text = ex.Message; } }
/// <summary> /// Create a new Course object. /// </summary> /// <param name="id">Initial value of the ID property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="credits">Initial value of the Credits property.</param> /// <param name="department">Initial value of the Department property.</param> public static Course CreateCourse(global::System.Int64 id, global::System.String name, global::System.String title, global::System.Byte credits, global::System.Int64 department) { Course course = new Course(); course.ID = id; course.Name = name; course.Title = title; course.Credits = credits; course.Department = department; return course; }
/// <summary> /// Deprecated Method for adding a new object to the Courses EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCourses(Course course) { base.AddObject("Courses", course); }