我的代码中有一个例外。我已经尝试将我的 int64 更改为 int32 但这并没有改变它。
在数据库中,表示“column_ID”的单元格具有数据类型 NUMBER。
问题出在此代码的第 7 行:
private void dataGridView_ArticleINVIA_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && e.RowIndex <= (sender as DataGridView).Rows.Count - 1)
{
try
{
Int64 id_riga = Convert.ToInt64((sender as DataGridView).Rows[e.RowIndex].Cells["column_ID"].Value);
//Exception thrown here:
int id_macchina = Convert.ToInt32((sender as
DataGridView).Rows[e.RowIndex].Cells["column_Machine"].Value);
FormRecipeNote PopUpNote = new FormRecipeNote(id_macchina,
"MODIFICA", id_riga, 0);
PopUpNote.ShowDialog(this);
PopUpNote.Dispose();
}
catch (Exception Exc)
{
FormMain.loggerSoftwareClient.Trace(this.Name + " " + Exc);
}
//DataGrid_ArticleINVIA();
}
}
错误是:
System.InvalidCastException: Object cannot be cast from DBNull to other types.
at System.DBNull.System.IConvertible.ToInt64(IFormatProvider provider)
at System.Convert.ToInt64(Object value)
at Software_Client.FormSendReceiveRecipe.dataGridView_ArticleINVIA_CellDoubleClick(Object sender, DataGridViewCellEventArgs e)
有人可以帮我解决这个问题吗?