Hi ,
In following function Compare(), I have a serious performance issue when I update a DataRow column. And I am unable to trace out the reason. Please do help me to get rid of this.
Where the problem is? (from compare(), the below line of code creates performance issue.)
adoRow2.Item("Diff") = intDiff 'Problem in this line,execution is fast when i comment this line.
How did I found the problem exists in that line?
I commented that particulat line and executed the code run very fast.
Private Sub Compare()
Dim adoRow1 As DataRow
Dim adoRow2 As DataRow
Dim adoRows() As DataRow
Dim intDiff As Integer
Dim intNew As Integer
Dim intOld As Integer
Dim intChanged As Integer
Dim blnIsNull As Boolean
Try
Select Case m_enuDataType
Case 0, 2
m_adoTable1.DefaultView.Sort ="DistItemNo, DistId, InvoiceNo, InvoiceLineNo,InvoiceDate"
m_adoTable2.DefaultView.Sort ="DistItemNo, DistId, InvoiceNo, InvoiceLineNo,InvoiceDate"
End Select
For Each adoRow1 In m_adoTable1.Rows
Select Case m_enuDataType
Case 0, 2
adoRows = m_adoTable2.Select("InvoiceLineNo = '" + PrepWhereValue(adoRow1.Item("InvoiceLineNo").ToString)
+ "'" + " AND InvoiceNo = '" + PrepWhereValue(adoRow1.Item("InvoiceNo").ToString)
+ "'" + " AND InvoiceDate = '" + PrepWhereValue(adoRow1.Item("InvoiceDate").ToString)
+ "'" + " AND OriginalDistId = '" + PrepWhereValue(adoRow1.Item ("DistId").ToString) + "'")
' If a matching row was found then compare the data in the rows.
If adoRows.GetUpperBound(0) = 0 Then
adoRow2 = adoRows(0)
intDiff = 0
blnIsNull = adoRow1.IsNull("SalesmanName")
If blnIsNull <> adoRow2.IsNull("SalesmanName") OrElse (Not blnIsNull AndAlso adoRow1.Item("SalesmanName").ToString <> adoRow2.Item("SalesmanName").ToString) Then intDiff += 1048576
blnIsNull = adoRow1.IsNull("SalesTerritoryNo")
If blnIsNull <> adoRow2.IsNull("SalesTerritoryNo") OrElse (Not blnIsNull AndAlso adoRow1.Item("SalesTerritoryNo").ToString <> adoRow2.Item("SalesTerritoryNo").ToString) Then intDiff += 2097152
blnIsNull = adoRow1.IsNull("SalesmanNo")
If blnIsNull <> adoRow2.IsNull("SalesmanNo") OrElse (Not blnIsNull AndAlso adoRow1.Item("SalesmanNo").ToString <> adoRow2.Item ("SalesmanNo").ToString) Then intDiff += 4194304
adoRow1.Item("Diff") = intDiff
adoRow2.Item("Diff") = intDiff 'Problem in this line,execution is fast when i comment this line.
If intDiff <> 0 Then intChanged += 1
ElseIf adoRows.GetUpperBound(0) = -1 Then
adoRow1.Item(
"Diff") = 100000000000000000
intOld += 1
Else
adoRow1.Item("Diff") = 0
For Each adoRow2 In adoRows
adoRow2.Item("Diff") = 0
Next '<< For Each adoRow2 In adoRows
End If '<< If adoRows.GetUpperBound(0) = 0 Then
End Select '<< Select Case m_enuDataType
Select Case m_enuDataType
Case 0, 2
For Each adoRow2 In m_adoTable2.Select("Diff=-1")
adoRow2.Item("Diff") = 100000000000000000
intNew += 1
Next '<< For Each adoRow2 In m_adoTable2.Select("Diff=-1")
End Select '<< Select Case m_enuDataType
If Not m_blnCancel Then
m_adoTable1.DefaultView.Sort ="Diff Desc"
m_adoTable2.DefaultView.Sort ="Diff Desc"
' End the loading of the data and fire an event to indicate that the loading of data is done.
End If '<< If Not m_blnCancel Then
Catch errException As ThreadAbortException
Catch errException As Exception
Throw errException
Finally
' If canceled then the tables will not be used by the calling GUI and should be disposed.
If Not m_adoTable1 Is Nothing Then m_adoTable1.Dispose()
If Not m_adoTable2 Is Nothing Then m_adoTable2.Dispose()
End If '<< If Not m_blnDone Then
End Try
End Sub
Private Function PrepWhereValue(ByVal v_strValue As String) As String
Try
If Not v_strValue Is Nothing Then Return v_strValue.Replace("'", "''")
Catch ex As Exception
Throw ex
End Try
End Function