Vb.net 我需要一个更快的方法来更新VB中的数据集

Vb.net 我需要一个更快的方法来更新VB中的数据集,vb.net,visual-studio,dataset,Vb.net,Visual Studio,Dataset,在VB中,我从一个数据集获取一些信息并更新另一个数据集。 数据集中大约有20万条记录,这需要很长时间。接近每千条记录2分钟 如果您对更快的方法有任何建议,请随时通知我 **编辑-我已经确定花费这么长时间的部分原因是每次添加新行时更新数据集,并将这些记录的计数输出到标签。我将更新移到循环之外,并得到一个错误。删除了ReportProgress和标签输出,错误消失。所以我想现在我正在寻找如何将这些信息发送到进度条或标签而不失败的建议。我认为输出到标签的时间比实际创建行的时间要长 Private Su

在VB中,我从一个数据集获取一些信息并更新另一个数据集。 数据集中大约有20万条记录,这需要很长时间。接近每千条记录2分钟

如果您对更快的方法有任何建议,请随时通知我

**编辑-我已经确定花费这么长时间的部分原因是每次添加新行时更新数据集,并将这些记录的计数输出到标签。我将更新移到循环之外,并得到一个错误。删除了ReportProgress和标签输出,错误消失。所以我想现在我正在寻找如何将这些信息发送到进度条或标签而不失败的建议。我认为输出到标签的时间比实际创建行的时间要长

Private Sub bgwUpdate_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgwUpdate.DoWork

        System.Threading.Thread.Sleep(1000)

        Dim intIndex As Integer = 0
        Dim strName As String
        Dim dblLatDegrees As Double
        Dim dblLatMinutes As Double
        Dim dblLatSeconds As Double
        Dim strLatDirection As String
        Dim dblLonDegrees As Double
        Dim dblLonMinutes As Double
        Dim dblLonSeconds As Double
        Dim strLonDirection As String

        ' Loop through all records in the CO DataTable
        For Each CORow As DataRow In TowersDataSet.CO

            strName = CStr(TowersDataSet.CO.Company_NameColumn.Table.Rows(intIndex).Item("Company_Name"))
            dblLatDegrees = CDbl(TowersDataSet.CO.Latitude_DegreesColumn.Table.Rows(intIndex).Item("Latitude_Degrees"))
            dblLatMinutes = CDbl(TowersDataSet.CO.Latitude_MinutesColumn.Table.Rows(intIndex).Item("Latitude_Minutes"))
            dblLatSeconds = CDbl(TowersDataSet.CO.Latitude_SecondsColumn.Table.Rows(intIndex).Item("Latitude_Seconds"))
            strLatDirection = CStr(TowersDataSet.CO.Latitude_DirectionColumn.Table.Rows(intIndex).Item("Latitude_Direction"))

            dblLonDegrees = CDbl(TowersDataSet.CO.Longitude_DegreesColumn.Table.Rows(intIndex).Item("Longitude_Degrees"))
            dblLonMinutes = CDbl(TowersDataSet.CO.Longitude_MinutesColumn.Table.Rows(intIndex).Item("Longitude_Minutes"))
            dblLonSeconds = CDbl(TowersDataSet.CO.Longitude_SecondsColumn.Table.Rows(intIndex).Item("Longitude_Seconds"))
            strLonDirection = CStr(TowersDataSet.CO.Longitude_DirectionColumn.Table.Rows(intIndex).Item("Longitude_Direction"))

            ' Create a new row with the information we gathered
            Dim updateRow As GPS_FunDataSet1.LocationsRow
            updateRow = GPS_FunDataSet1.Locations.NewLocationsRow

            updateRow.name = strName
            updateRow.type = "Tower"
            updateRow.latitude = convert.toDecimal(CStr(dblLatDegrees) + " " + CStr(dblLatMinutes) + " " + CStr(dblLatSeconds) + strLatDirection)
            updateRow.longitude = convert.toDecimal(CStr(dblLonDegrees) + " " + CStr(dblLonMinutes) + " " + CStr(dblLonSeconds) + strLonDirection)

            ' Add the row to the DataTable
            GPS_FunDataSet1.Locations.Rows.Add(updateRow)

            ' Update the Actual database
            Try
                LocationsBindingSource.EndEdit()
                LocationsTableAdapter.Update(GPS_FunDataSet1.Locations)
            Catch ex As Exception
                Console.WriteLine("Failure")
            End Try

            bgwUpdate.ReportProgress(intIndex + 1)
            intIndex += 1
        Next

    End Sub

您只需在循环后更新数据库一次,而不是总是这样。因此,将LocationsTableAdapter.UpdateGPS_FundaataSet1.Locations移到循环后面。然后可以在一批中更新/插入所有内容。我将该行移到循环之后,在System.Windows.Forms.dllI中首次出现“System.InvalidOperationException”类型的异常。我建议更改您问题的标题,以便更好地匹配您现在提出的问题。