【问题标题】:'DataGridView' VS 'DataGrid' when Convert to 'DataSet'?转换为“DataSet”时的“DataGridView”VS“DataGrid”?
【发布时间】:2010-10-08 09:54:45
【问题描述】:

我已成功将 Excel 数据与 DataGridView 控制器绑定。 然后我尝试将 DataGridView 内容保存到 xml 文件。 我想实现为 belwo,但抛出异常。 如何使用 DataGridView 修复它? (使用VS2008)

// 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);  

【问题讨论】:

    标签: c# datagrid datagridview c#-3.0


    【解决方案1】:

    在调试器中使用断点,检查 dataGridView1.DataSource 的实际类类型。

    例如,您可能会发现,如果您在网格视图和数据集之间使用BindingSource 类,则视图数据源不是DataSet,而是包装了@ 的System.Data.DataView 987654325@。 然后你必须使用:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-06
      • 2017-08-27
      • 2010-12-22
      • 1970-01-01
      • 1970-01-01
      • 2015-07-20
      • 2020-10-15
      • 2020-05-20
      相关资源
      最近更新 更多