C# 从System.Data.Common.DataRecordInternal检索值

C# 从System.Data.Common.DataRecordInternal检索值,c#,wpf,C#,Wpf,我希望检索绑定到sqlexecute查询的datagrid的值 defects.DefectsDataGrid.DataContext = searchQuery.ExecuteReader(); 然后,我使用SelectedCellsChanged事件对选定的DataGridRow进行处理 当我在中放置断点时,我可以看到System.Data.Common.DataRecordInternal>非公共成员>\u值下面的值。但我不知道如何引用_值 谢谢你一如既往的帮助 代码 看起来您需

我希望检索绑定到sqlexecute查询的datagrid的值

    defects.DefectsDataGrid.DataContext = searchQuery.ExecuteReader();
然后,我使用SelectedCellsChanged事件对选定的DataGridRow进行处理

当我在中放置断点时,我可以看到System.Data.Common.DataRecordInternal>非公共成员>\u值下面的值。但我不知道如何引用_值

谢谢你一如既往的帮助

代码


看起来您需要使用
DataReader
将记录强制转换到
IDataRecord

看看这个答案:

我将上述内容更改为以下内容,这为我提供了DataRowView的数据类型,而不是DataRecordInternal

    defects.DefectsDataGrid.ItemsSource = DataTable.DefaultView;
这使我能够轻松地在事件中引用行

    private void DefectsDataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
    {
        //Retrieve selected value from the row selected
        DataRowView dataRow = (DataRowView)DefectsDataGrid.SelectedItem;
        string phrase = dataRow[2];
    }

Franssu,我总是将结果放入datareader或datatable中,我使用它们没有问题,但我想看看是否可以直接绑定到ExecuteReader,这似乎很好,但从事件处理程序检索值导致了我的问题。有什么想法吗?
    defects.DefectsDataGrid.ItemsSource = DataTable.DefaultView;
    private void DefectsDataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
    {
        //Retrieve selected value from the row selected
        DataRowView dataRow = (DataRowView)DefectsDataGrid.SelectedItem;
        string phrase = dataRow[2];
    }