Question : increase database access performance - ms-access

I have a code [attached] which takes two tables at a time from an access databases, compare values for each row and column and if it finds any differences it reports to the user.

Unfortunately it becomes slower and slower as the database grow.

I really want it fast and i don't know what to do. should i use Threading. I have attached the code

Anthony

    Public Function showDifferences(ByVal ds As String, ByVal co As System.Data.OleDb.OleDbConnection) As Boolean
        Dim z As Integer
        Dim v, p, vname As String

        z = 0

        showDifferences = False
        'there are several tables and pick one at a time- they are in the table tblRecords
        'e.g. compare values in table [master] against those in table [vmaster]

        For t As Long = 0 To tblRecords.Rows.Count - 1
            Application.DoEvents()
            'exclude these tables
            If sectionsToEculude(tblRecords.Columns("recname").ColumnName) = True Then Continue For
            If Trim(mainver).Length = 0 Then
                tstr = "SELECT * FROM [" & tblRecords.Rows(t)("recname") & "] " & ds
            Else
                tstr = "SELECT * FROM [" & mainver & tblRecords.Rows(t)("recname") & "] " & ds
            End If

            cm = New OleDb.OleDbCommand
            cm.CommandText = tstr
            cm.Connection = co
            dr = cm.ExecuteReader
            If dr.HasRows Then
                While dr.Read
                    criteria = ""
                    'construct the sql criteria for each table
                    criteria = Trim(Mid(ds, 1, ds.Length - 1)) & " and "
                    For i As Int16 = 1 To tblRecords.Rows(t)("nid")
                        If Not IsDBNull(dr(tblRecords.Rows(t)("id" & (i - 1).ToString))) Then
                            If Not IsNumeric(dr(tblRecords.Rows(t)("id" & (i - 1).ToString))) Then
                                criteria = criteria & tblRecords.Rows(t)("id" & i - 1) & "='" & dr(tblRecords.Rows(t)("id" & (i - 1).ToString)) & "' and "
                            Else
                                criteria = criteria & tblRecords.Rows(t)("id" & i - 1) & "=" & dr(tblRecords.Rows(t)("id" & (i - 1).ToString)) & " and "
                            End If
                        Else
                            criteria = criteria & tblRecords.Rows(t)("id" & i - 1) & " Is null and "
                        End If
                    Next
                    criteria = Mid(criteria, 1, criteria.Length - 5)

                    If Trim(mainver).Length = 0 Then
                        tstr = "SELECT * FROM [v" & tblRecords.Rows(t)("recname") & "] " & criteria & ";"
                    Else
                        tstr = "SELECT * FROM [" & tblRecords.Rows(t)("recname") & "] " & criteria & ";"
                    End If

                    'now i have the entire SQL statement and the criteria appended to it.

                    cmd = New OleDb.OleDbCommand
                    cmd.CommandText = tstr
                    cmd.Connection = co

                    ddr = cmd.ExecuteReader
                    If tblRecords.Rows(t)("recname") = "master" Then recordExists = False 'not in verification
                    'reader [dr] is holding values for table [master]
                    'reader [ddr] is holding values for table [vmaster] for example

                    If ddr.HasRows Then
                        recordExists = True
                        'check duplicates
                        dup1.Clear()
                        dup2.Clear()
                        While ddr.Read
                            'compare field value by field value
                            'if any is different [showDifferences] is true
                            'report
                            For f As Int16 = idNames.Count To dr.FieldCount - 1
                                vname = dr.GetName(f)
                                If IsDBNull(dr(f)) Then : v = Nothing : Else : v = Trim(dr(f)) : End If
                                If IsDBNull(ddr(vname)) Then : p = Nothing : Else : p = Trim(ddr(vname)) : End If
                                If Not variablesToExclude(vname) Then
                                    If v <> p Then
                                        showDifferences = True
                                        ddr.Close()
                                        ddr = Nothing
                                        cmd.Dispose()
                                        Exit Function
                                    End If
                                End If
                            Next
                        End While

                    Else
                        'tell user if the record is not found in [vmaster]
                        If tblRecords.Rows(t)("recname") = "master" Then recordExists = False
                    End If
                    ddr.Close()
                    ddr = Nothing
                    cmd.Dispose()
                    Application.DoEvents()
                End While

            End If
            dr.Close()
            dr = Nothing
            cm.Dispose()
        Next
        cmd.Dispose()
    End Function

Answer : increase database access performance - ms-access

Aaaaahh ... ok the problem is that you don't have to provide the data element ... all you do is to procide the name of the function.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minHeight="0" width="910" height="1000"
			   creationComplete="serviceEventList.send()">
	<fx:Declarations>
		<mx:HTTPService id="serviceEventList" url="http://10.1.1.203/asp/list/event_events_liste.asp" result="resultHandler(event)" fault="faultHandler(event)" />
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			
			[Bindable]
			private var eventList:ArrayCollection;
			
			private function resultHandler(event:ResultEvent):void {
				eventList = event.result.row;
				//Alert.show(eventList.getItemAt(0).EID.toString());
			}
			private function faultHandler(event:FaultEvent):void {
				Alert.show(event.fault.faultString, event.fault.faultCode);
			}
			
			private function listItemRendFunc(item:Object):ClassFactory {
				var cla:Class = event_liste;
				switch (item.type) {
					case "P1V":
						cla = event_liste;
						break;
					case "P1A":
						cla = event_liste2;
						break;
					default:
						break;
				}
				return new ClassFactory(cla);
			}
			
		]]>
	</fx:Script>
	
	<s:Button x="10" y="10.25" label="Button"/>
	<s:Button x="10" y="39.7" label="Button"/>
	<s:Button x="10" y="69.15" label="Button"/>
	<s:DataGroup x="105" y="14" width="700" height="200" dataProvider="{eventList}" itemRendererFunction="listItemRendFunc">
		<s:layout>
			<s:TileLayout/>
		</s:layout>
	</s:DataGroup>

</s:Application>
Random Solutions  
 
programming4us programming4us