datagridview的数据源未得到更新
本文关键字:更新 数据源 datagridview | 更新日期: 2023-09-27 18:29:05
我绑定DataGridView的DataSource属性,并使用DataAdaptor更新它,以及它的工作。现在我正试图将Excel文件中的DataSource与DataGridView的DataSource合并,并将这些合并DataSource保存在数据库中,2个数据源正在进行合并,但DataAdaptor无法更新数据库中的合并数据源,即使我在更新DataAdaptor时也没有遇到任何错误,以下是合并和保存DataSource 的代码
//Code for Merging DataSources
byte[] dataTable = GetExcelFileByteArray();
//ExcelDataTable is of type DataTable
ExcelDataTable = GetTableDataOfByteArrayOfExcel(dataTable);
//dgvAllGridView is DataGridVIew
DataTable _dgvDataTable = this.dgvAllGridView.DataSource as DataTable;
if (!ExcelDataTable.Columns.Contains("ID"))
ExcelDataTable.Columns.Add("ID", _dgvDataTable.Columns["ID"].GetType()).SetOrdinal(0);
_dgvDataTable.Merge(ExcelDataTable, true, MissingSchemaAction.Ignore);
dgvAllGridView.DataSource = _dgvDataTable;
//Code for Updatating DataAdaptor
//DataAdaptor is a OleDBDataAdaptor
DataAdaptor.UpdateCommand = new OleDbCommandBuilder(DataAdaptor).GetUpdateCommand();
DataAdaptor.InsertCommand = new OleDbCommandBuilder(DataAdaptor).GetInsertCommand();
DataAdaptor.Update((DataTable)dgvAllGridView.DataSource);
在上一个代码中添加了dgvAllGridView.DataSource = _dgvDataTable;
吗?它将刷新DGV数据源。。