private void BtnAdd_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(TxtTitle.Text) && !string.IsNullOrEmpty(TxtID.Text) && comboBoxCredits.Text != null && comboBoxDepartments.Text != null && comboBoxInstructors.Text != null) { using (var db = new SchoolEntities()) { // converting id text to number Int32.TryParse(TxtID.Text, out Int32 ID); // converting department name to department id var deptID = from o in db.Department where o.Name.Equals(comboBoxDepartments.SelectedItem.ToString()) select o.DepartmentID; Int32.TryParse(deptID.First().ToString(), out Int32 finalDeptID); // converting credits from combobox selection to number Int32.TryParse(comboBoxCredits.SelectedItem.ToString(), out Int32 credits); var course = new Course { CourseID = ID, Title = TxtTitle.Text, Credits = credits, DepartmentID = finalDeptID }; db.Course.Add(course); // course instructor part // missing from model (?) //var courseInstructor = db. db.SaveChanges(); dataGridView1.DataSource = db.Course.ToList(); } TxtID.ResetText(); TxtTitle.ResetText(); comboBoxCredits.SelectedItem = null; comboBoxDepartments.SelectedItem = null; comboBoxInstructors.SelectedItem = null; } }