如何合并以两种不同方式构建的 2 个 DataView?

How can I merge 2 DataView built in 2 different way?

我不是 C# 开发人员,我发现自己在处理一个巨大的 C# 应用程序...拥抱...

现在,我正在尝试用更多数据填充现有的 DataGrid,这些数据已经 'created' 以不同的方式......让我告诉你我的意思。

现有DataView是这样生成的:

Dim lDataSet As System.Data.DataSet
Dim lSqlCommand As New System.Data.SqlClient.SqlCommand
Dim lConvert As New PeoplePlanner.Common.Data.Convert

lSqlCommand.CommandType = CommandType.StoredProcedure
lsqlCommand.CommandText = "AccessIntegrationEmployeeInboundSearch"

lDataSet = objDatabase.GetDataSet(lSqlCommand)

If Not IsNothing(lDataSet) Then
    objDataView = lDataSet.Tables(0).DefaultView
End If

该代码中可能缺少一些东西,但希望它足以获得概述。它使用存储过程 (SP) 从数据库中获取一些数据,它 returns 里面的结果 'lDataSet' 然后我们做 'objDataView = lDataSet.Tables(0).DefaultView'.

现在,我想要 'merge in' 的新数据具有相同的字段,但它不是 SP 的响应,而是我创建的操作的响应,该操作 returns 支持 OnBoardingEmployee 列表(让我们这样称呼它)如果我只想正确显示该列表中的数据,这就是我所做的:

 Dim lDataView As System.Data.DataView

 Dim op = CoreInjector.Inject(Of IGetAllDataHubIncomingMessagesToBeProcess).Execute()
 lDataView = Common.Detail.DataGridOperationHelper.ConvertToDataTable(op.OnBoardingEmployee).DefaultView

 objDataView = lDataView

其中:

现在我基本上想合并、加入、添加等等 为第一个 table 创建的 objDataView: objDataView = lDataSet.Tables(0).DefaultView

与我之后创建的那个:

 lDataView = Common.Detail.DataGridOperationHelper.ConvertToDataTable(x.OnBoardingEmployee).DefaultView

我该怎么做? :'(

它们具有相同的数据结构,或者更确切地说它们使用相同的视图。

感谢您的帮助:)

我已经开始工作了:)这是我的实现:

        Dim employeeJSONTable As DataTable
        Dim employeeExistingTable As DataTable
        Dim myDataRow As DataRow
        Dim employeeID As Integer

        if Request.QueryString.Get("Function") = "HubInbound" then
            Dim employeeJSONList = CoreInjector.Inject(Of IGetAllDataHubIncomingMessagesToBeProcess).Execute()
            employeeJSONTable = Common.Detail.DataGridOperationHelper.ConvertToDataTable(employeeJSONList.OnBoardingEmployee)
            employeeJSONTable.PrimaryKey = New DataColumn(){ employeeJSONTable.Columns("EmployeeID")}
        End If

        lDataSet = objDatabase.GetDataSet(lSqlCommand)
        employeeExistingTable = lDataSet.Tables(0)

        For Each row As DataRow In employeeExistingTable.Rows

            employeeID = row.Item("EmployeeID")

            myDataRow = employeeJSONTable.Rows.Find(employeeID)

            if (myDataRow Is Nothing) then
                employeeJSONTable.ImportRow(row)
            End If

        Next row

        If Not IsNothing(employeeJSONTable.DefaultView) And Request.QueryString.Get("Function") = "HubInbound" Then
                objDataView = employeeJSONTable.DefaultView
        Elseif Not IsNothing(lDataSet) Then
                objDataView = lDataSet.Tables(0).DefaultView
        End if