help me how to convert BindingSource to DataTable ???
-
Hi, After binding datagridview with dataset, when users modify, add or delete the datagridview rows, I want to use datasource of datagridview to run OleCommandBuilder object. But an error appears "Unable to cast object of type bindingsource to type datatable" I am very confused and have you help me how to convert nimdingsource to datatable..... [Code] OleDbDataAdapter adap = new OleDbDataAdapter("Select * from tblVATTU where VATTU_ID = ''", con.con); temp = new DataTable(); MessageBox.Show(dgvVATTU.DataSource.GetType().ToString()); temp = (DataTable)dgvVATTU.DataSource ; // error is here OleDbCommandBuilder buider = new OleDbCommandBuilder(adap); adap.FillSchema(temp, SchemaType.Source); adap.Fill(temp);
It seem to be a solution or an answer.
-
Hi, After binding datagridview with dataset, when users modify, add or delete the datagridview rows, I want to use datasource of datagridview to run OleCommandBuilder object. But an error appears "Unable to cast object of type bindingsource to type datatable" I am very confused and have you help me how to convert nimdingsource to datatable..... [Code] OleDbDataAdapter adap = new OleDbDataAdapter("Select * from tblVATTU where VATTU_ID = ''", con.con); temp = new DataTable(); MessageBox.Show(dgvVATTU.DataSource.GetType().ToString()); temp = (DataTable)dgvVATTU.DataSource ; // error is here OleDbCommandBuilder buider = new OleDbCommandBuilder(adap); adap.FillSchema(temp, SchemaType.Source); adap.Fill(temp);
It seem to be a solution or an answer.
Hi, You need to fill dataset first,
Dataset dsFunction = New DataSet(); OleDbDataAdapter adap = new OleDbDataAdapter("Select * from tblVATTU where VATTU_ID = ''", con.con); temp = new DataTable(); adap.Fill(dsFunction); temp = dsFunction.Tables[0];
Mubashir Software Architect Storan Technologies Inc, USA Every job is a self portrait of the person who did it.
-
Hi, After binding datagridview with dataset, when users modify, add or delete the datagridview rows, I want to use datasource of datagridview to run OleCommandBuilder object. But an error appears "Unable to cast object of type bindingsource to type datatable" I am very confused and have you help me how to convert nimdingsource to datatable..... [Code] OleDbDataAdapter adap = new OleDbDataAdapter("Select * from tblVATTU where VATTU_ID = ''", con.con); temp = new DataTable(); MessageBox.Show(dgvVATTU.DataSource.GetType().ToString()); temp = (DataTable)dgvVATTU.DataSource ; // error is here OleDbCommandBuilder buider = new OleDbCommandBuilder(adap); adap.FillSchema(temp, SchemaType.Source); adap.Fill(temp);
It seem to be a solution or an answer.
If the datagrid is empty, then fill it first. And then try to bind the table to the datasource.
DataGrid1.Rows.Add(1); DataGrid1.Rows[1].Cells[1].Value = "Some String";
Keshav Kamat :) India