【发布时间】:2018-02-14 16:23:26
【问题描述】:
我遇到以下异常
无法将“system.windows.forms.bindingsource”类型的对象转换为“system.data.datatable”类型
这是我的方法
private void GridViewStudentsList_RowValidated(object sender, DataGridViewCellEventArgs e) {
try {
BindingSource bindingSource = (BindingSource) GridViewStudentsList.DataSource;
DataTable changes = (DataTable) bindingSource.DataSource;
changes.GetChanges();
if (changes != null) {
OracleConnection con = new OracleConnection(connection);
con.Open();
OracleDataAdapter adapter = new OracleDataAdapter();
OracleCommandBuilder mcb = new OracleCommandBuilder(adapter);
adapter.UpdateCommand = mcb.GetUpdateCommand();
adapter.Update(changes);
changes.AcceptChanges();
MessageBox.Show("Cell Updated");
con.Close();
return;
}
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
【问题讨论】:
-
那么你有没有试过调试它并偷看
bindingSource.DataSource是什么类型? -
bindingSource.DataSource = 'bindingSource.DataSource' 引发了“System.NullReferenceException”类型的异常
-
bindingSource.DataSource = {College_Management_System.ViewStudentData}
-
现在我已将 DataTable 更改为 DataSet 现在它可以工作但再次显示错误\“由于对象的当前状态,操作无效”
-
新的异常在哪一行抛出?