开发者

'DataGridView' VS 'DataGrid' when Convert to 'DataSet'?

开发者 https://www.devze.com 2023-01-19 00:59 出处:网络
I bound excel data with DataGridView controller successfully. Then I try to save the DataGridView contents to xml file.

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 onl开发者_如何学JAVAine tutorial posted as this style below
DataSet ds = (DataSet)(dataGrid1.DataSource);  


Using a breakpoint in the debugger, check what class type dataGridView1.DataSource actually is.

For instance, you might find that if you are using a BindingSource class between the grid view and the data set, that the views data source is not a DataSet, but instead a System.Data.DataView which wraps the DataSet. You would then have to use:

DataSet ds = ((DataView)dataGridView1.DataSource).Table.DataSet;
0

精彩评论

暂无评论...
验证码 换一张
取 消