private void Createsessions_Click(object sender, EventArgs e) { if (type.Text != "" && Gid.Text != "" && Scount.Text != "" && subNamelist.Text != "" && subcodeList.Text != "" && lecList.Items.Count != 0) { foreach (DataGridViewRow row in sessionList.Rows) { if (row.Cells[1].Value.ToString().Equals(subcodeList.Text) && row.Cells[2].Value.ToString().Equals(type.Text) && row.Cells[3].Value.ToString().Equals(Gid.Text)) { if (type.Text == "Practical") { if (row.Cells[4].Value.ToString().Equals(subBox.Text)) { System.Windows.Forms.MessageBox.Show("This session already added !", "Warning").ToString(); return; } } else { System.Windows.Forms.MessageBox.Show("This session already added !", "Warning").ToString(); return; } } } sessionModel sessionmodel = new sessionModel(); sessionmodel.SubName = subNamelist.Text; sessionmodel.subCode = subcodeList.Text; sessionmodel.Type = type.Text; sessionmodel.groupId = Int32.Parse(Gid.Text); sessionmodel.subgId = subBox.Text; sessionmodel.studentcount = Int32.Parse(Scount.Text); sessionmodel.lec = ""; for (int i = 0; i < lecList.Items.Count; i++) { sessionmodel.lec = sessionmodel.lec + lecList.Items[i].Text + ","; } sessionmodel.lecturers = lec; session session = new session(); session.insertSessions(sessionmodel); lecList.Items.Clear(); lecturerlist.Text = ""; subNamelist.Text = ""; subcodeList.Text = ""; lecturerbox.DataSource = session.getLectures(); subjectBox.DataSource = session.getSubjects(); GroupBox.DataSource = session.getGroupID(); //sessionList.DataSource = session.getSessiondatatoTable(); sessionList.DataSource = session.getSessiondatatoTable(); flowLayoutPanel1.Controls.Clear(); for (int i = 0; i < session.getSessiondatatoTable().Rows.Count; i++) { show_data(session.getSessiondatatoTable(), i); } } else { string ans = System.Windows.Forms.MessageBox.Show("Please fill all the require fields !", "Warning").ToString(); } }