private void dgSearchContract_CellClick(object sender, DataGridViewCellEventArgs e) { try { string str = dgSearchContract.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); Admin Bind = new Admin(); ArrayList data_contract = Bind.BindAllContractDetails(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 + 8) { string ContractNumber = (string)data_contract[i]; string ContractName = (string)data_contract[i + 1]; string ContractDescription = (string)data_contract[i + 2]; string ContractTimePeriod = (string)data_contract[i + 3]; DateTime ContractStartDate = (DateTime)data_contract[i + 4]; DateTime ContractEndDate = (DateTime)data_contract[i + 5]; string ContractStatus = (string)data_contract[i + 6]; string ContractInfo = (string)data_contract[i + 7]; tbSearchContractNumber.Text = ContractNumber; tbSearchContractName.Text = ContractName; tbSearchContractDescription.Text = ContractDescription; tbSearchContractTime.Text = ContractTimePeriod; tbSearchContractStartDate.Text = ContractStartDate.ToShortDateString(); tbSearchContractEndDate.Text = ContractEndDate.ToShortDateString(); tbSearchContractStatus.Text = ContractStatus; tbSearchContractInfo.Text = ContractInfo; } } } 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); } }