private void btnGenerateReport_Click(object sender, EventArgs e) { try { List <string> selectedMonth = (List <string>)lstMonth.SelectedItems.Cast <String>().ToList(); int selectedYear = Convert.ToInt32(cmbYear.SelectedItem.ToString()); int? BU = null; var AccountList = new List <Account>(); if (rbBUList.Checked) { BU = Convert.ToInt32(lstBUAcc.SelectedValue); } else { foreach (Account item in lstBUAcc.SelectedItems) { Account a = new Account(); a.AccountID = Convert.ToInt32(item.AccountID); AccountList.Add(a); } } AccountMonthRevenue accMonthRevenue = new AccountMonthRevenue(); DataSet ds; if (cmbReportType.SelectedItem.ToString() == "Highest Margin") { ds = accMonthRevenue.GetPeopleWithHighestMargin(Convert.ToInt32(txtNoOfPeople.Text), BU, AccountList, selectedYear, selectedMonth); } else { ds = accMonthRevenue.GetPeopleWithLowestMargin(Convert.ToInt32(txtNoOfPeople.Text), BU, AccountList, selectedYear, selectedMonth); } dgvReportView.AutoGenerateColumns = true; dgvReportView.DataSource = ds.Tables[0]; dgvReportView.AutoResizeColumns(); dgvReportView.Show(); } catch (Exception ex) { MessageBox.Show("An error occured while generating the report.\nPlease try again in sometime."); } }