【发布时间】:2013-09-08 15:49:23
【问题描述】:
返回 Convert.ToInt32(dataGridView1[0, Row].Value); 时出错它说“对象不能从 DBNull 转换为其他类型。”我在学生 ID 上的数据库字段是 int。这是我的代码:
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();
}
【问题讨论】:
-
如果您的代码在数据库中找到空值,您希望您的代码做什么?
标签: c# sql-server