value of Identity column returning null when retrieved by value in dataGridView
Posted
by Raven Dreamer
on Stack Overflow
See other posts from Stack Overflow
or by Raven Dreamer
Published on 2010-06-10T14:57:05Z
Indexed on
2010/06/10
15:02 UTC
Read the original article
Hit count: 321
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?
© Stack Overflow or respective owner