private void dgOngoing_CellClick(object sender, DataGridViewCellEventArgs e) { try { string str = dgOngoing.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); Admin Bind = new Admin(); ArrayList data_contract = Bind.BindOngoingContract(str); if (data_contract.Count == 0) { MessageBox.Show("NO DATA MATCH WITH DATABASE RECORDS", "NO DATA FOUND", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { for (int i = 0; i < data_contract.Count; i = i + 5) { string ContractNumber = (string)data_contract[i]; string ContractName = (string)data_contract[i + 1]; string ContractTimePeriod = (string)data_contract[i + 2]; string ContractEndDate = (string)data_contract[i + 3]; string ContractStatus = (string)data_contract[i + 4]; tbEditContractNumber.Text = ContractNumber; tbEditContractName.Text = ContractName; tbEditContractTimePeriod.Text = ContractTimePeriod; tbEditContractEndDate.Text = ContractEndDate; tbEditContractStatus.Text = ContractStatus; } } } catch (SqlException) { MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (InvalidOperationException) { MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error); } }