我需要一种更快的方法来更新VB中的DataSet

时间:2014-10-30 11:45:43

标签: vb.net visual-studio dataset

在VB中,我从一个dataSet获取一些信息并更新另一个。 DataSet中有近200k条记录,需要很长时间。每千条记录接近2分钟。

有关更快方法的任何建议,请随时通知我。

**编辑 - 我已经确定它花费这么长时间的原因部分是由于每次添加新行时更新DataSet并将这些记录的计数输出到标签。我将UPDATE移到了循环之外并出现了错误。删除了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

0 个答案:

没有答案