I bound excel data with DataGridView controller successfully.
Then I try to save the DataGridView contents to xml file.
I want to implement as belwo, but throw exception.
How can I fix it using DataGridView? (VS2008 used)
// I tried to implement using this style.But throw exception.
DataSet ds = (DataSet)(dataGridView1.DataSource);
// One online tutorial posted as this style below
DataSet ds = (DataSet)(dataGrid1.DataSource);
Using a breakpoint in the debugger, check what class type
dataGridView1.DataSourceactually is.For instance, you might find that if you are using a
BindingSourceclass between the grid view and the data set, that the views data source is not aDataSet, but instead aSystem.Data.DataViewwhich wraps theDataSet.You would then have to use: