Reputation: 3834
I bind DataSource property of DataGridView and update it by using DataAdaptor, and its working. Now I am trying to merge DataSource from Excel file with DataSource of DataGridView and save those merge DataSource in Database, 2 datasource getting merge, but DataAdaptor unable to update this merge datasource in database, even I dont get any error while updating DataAdaptor, Here is code for merging and saving 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);
Upvotes: 0
Views: 437
Reputation: 5719
Have add dgvAllGridView.DataSource = _dgvDataTable;
in last code ?
It will refresh your DGV datasource ..
Upvotes: 1