Hey guys, i have a data grid view that i would like to grab an item from and then use it as a selection. I do this because in the form i only want to save data that is already in the database as my business rules are very strict, so to save people having to type it in perfectly, they just have to select it from the data grid view and their selection will be saved into the database. So in previous cases i have implemented it like this to grab the person ID and it works fine.
the code i used for person ID is as follows:
if (dgvPersonIDMedical.SelectedCells.Count !=0)
{
int selectedrowindex1 = dgvPersonIDMedical.SelectedCells[0].RowIndex;
DataGridViewRow selectedRow1 = dgvPersonIDMedical.Rows[selectedrowindex1];
medPersonID = Convert.ToInt16(selectedRow1.Cells[0].Value);
}
the one i am trying to use now is a string so i tried a convert.to string and it is not working, here is my code with the insert statement
if (dgvMedical.SelectedCells.Count !=0)
{
int selectedrowindex1 = dgvMedical.SelectedCells[0].RowIndex;
DataGridViewRow selectedRow1 = dgvMedical.Rows[selectedrowindex1];
conditionType = Convert.ToString(selectedRow1.Cells[0].Value);
}
try
{
medicalTableAdapter.Insert(Convert.ToInt32(medPersonID), conditionType, medicareTXT.Text, doctorTXT.Text, healthFundTXT.Text, memberNumberTXT.Text, ambulancefundTXT.Text, medicationTXT.Text);
}
catch (Exception)
{
MessageBox.Show("Error. That ID already exists within the medical table");
}
my code comppiles fine but keeps bringing up the catch block which means i messed something up somewhere, can anyone tell me where?
thanks for your time!