-6
我遇到以下异常无法投型“system.windows.forms.bindingsource”对象键入“system.data.datatable”
无法投类型的对象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'是什么? – Matten
bindingSource.DataSource ='bindingSource.DataSource'抛出'System.NullReferenceException'类型的异常 – Suriyan
bindingSource.DataSource = {College_Management_System.ViewStudentData} – Suriyan