Sunday, 8 September 2013

Im having an error Object cannot be cast from DBNull to other types

Im having an error Object cannot be cast from DBNull to other types

I have an error on return Convert.ToInt32(dataGridView1[0, Row].Value); it
says that 'Object cannot be cast from DBNull to other types.' My database
field on student ID is int. Here is my code:
public int GetStudentID()
{
// The Student ID is the first cell of the current row
int Row = dataGridView1.CurrentRow.Index;
return Convert.ToInt32(dataGridView1[0, Row].Value);
}
public string GetISBN()
{
// The ISBN is the second cell of the current row
int Row = dataGridView1.CurrentRow.Index;
return dataGridView1[1, Row].Value.ToString();
}

No comments:

Post a Comment