无法将'system.windows.forms.bindingsource'类型的对象强制转换为'system.data.datatable'

时间:2017-09-06 08:54:03

标签: c# .net c#-4.0 .net-core

我遇到以下异常

  

无法将'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);
    }
}

1 个答案:

答案 0 :(得分:0)

  

我犯了一些小错误

以下代码是工作代码

No. of Occurences(view)