value of Identity column returning null when retrieved by value in dataGridView
- by Raven Dreamer
Greetings.
I'm working on a windows forms application that interacts with a previously created SQL database. Specifically, I'm working on implementing an "UPDATE" query.
for (int i = 0; i < dataGridView1.RowCount; i++)
{
string firstName = (string)dataGridView1.Rows[i].Cells[0].Value;
string lastName = (string)dataGridView1.Rows[i].Cells[1].Value;
string phoneNo = (string)dataGridView1.Rows[i].Cells[2].Value;
short idVal = (short)dataGridView1.Rows[i].Cells[3].Value;
this.contactInfoTableAdapter.UpdateQuery(firstName, lastName, phoneNo, idVal);
}
The dataGridView has 4 columns, First Name, Last Name, Phone Number, and ID (which was created as an identity column when I initially formed the table in SQL). When I try to run this code, the three strings are returned properly, but dataGridView1.Rows[i].Cells[3].Value is returning "null".
I'm guessing this is because it was created as an identity column rather than a normal column. What's a better way to retrieve the relevant ID value for my UpdateQuery?