private void btnSubmit_Click_1(object sender, EventArgs e) { StartDate = dtStartDate.Value; EndDate = dtEndDate.Value; int result = DateTime.Compare(EndDate, StartDate); if (result < 0) { errProvider.SetError(dtEndDate, "Election end date should be greater than start date"); } else { errProvider.SetError(dtEndDate, ""); var election = new Election { ElectionId = txtElectionId.Text.Trim().ToUpper(), Post = txtElectionPost.Text.Trim().ToUpper(), NoOfCandidates = Convert.ToInt32(cmbNoOfCandidates.Text), StartDate = dtStartDate.Value, EndDate = dtEndDate.Value }; if (AddNewElection.Read(txtElectionId.Text) > 0) { var newElection = AddNewElection.NewElection(election); MessageBox.Show(newElection > 0 ? @"Successfully add a new election" : @"Error adding a new election", @"eVoting System"); } else { MessageBox.Show(@"Duplicate election Id is not allowed", @"eVoting System");; } } lstViewElection.Items.Clear(); cmbNoOfCandidates.SelectedIndex = -1; btnView_Click(null, null); }