Datasource of datagridview not getting update
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 = GetTableDataOfByteArrayOfExcel(dataTable);
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.UpdateCommand = new
OleDbCommandBuilder(DataAdaptor).GetUpdateCommand();
DataAdaptor.InsertCommand = new
OleDbCommandBuilder(DataAdaptor).GetInsertCommand();
DataAdaptor.Update((DataTable)dgvAllGridView.DataSource);
No comments:
Post a Comment