Bonjour,

J'ai écrit une petite fonction qui récupère le contenu d'une table SQLite dans un dataset afin de mettre à jour le contenu d'un champ. En fait, je calcule la distance entre la position actuelle et les différents points de la table. Quand je regarde le temps d'exécution de cette fonction, la première exécution du code prend 1000 millisecondes tandis que les suivantes sont quasi instantanées (0 millisecondes). Quelqu'un aurait-il une idée du pourquoi ?

Voilà la fonction :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
''' <summary>
''' Calculate the distances between actual position and the selected points
''' </summary>
''' <param name="querySelected">The query corresponding to the selected points.</param>
Private Sub CalculateDistance(ByVal querySelected As String)
	' get the points and set it to a dataadapter
	Dim query As String = "select * from Point where idProject=" & idProject & querySelected & " ;"
	Dim adapter As New SQLiteDataAdapter(query, db)
	Dim pointsSet As New DataSet
	adapter.Fill(pointsSet, "Point")
	' calculate the distance
	Dim pointsRow As DataRow
	For i As Integer = 0 To pointsSet.Tables("Point").Rows.Count - 1
		pointsRow = pointsSet.Tables("Point").Rows(i)
		pointsRow("calcDistance") = CalcDistance(CDbl(pointsRow("x")), CDbl(pointsRow("y")), gpsPos.Easting, gpsPos.Northing)
	Next
	pointsRow = Nothing
	' define the update command for calculated distance
	Dim cmdUpdate As SQLiteCommand = New SQLiteCommand("update point set calcDistance=? where idProject=? and idPoint =?", db)
	With cmdUpdate.Parameters.Add("@p1", DbType.Decimal)
		.SourceColumn = "calcDistance"
		.SourceVersion = DataRowVersion.Current
	End With
	With cmdUpdate.Parameters.Add("@p2", DbType.Int32)
		.SourceColumn = "idProject"
		.SourceVersion = DataRowVersion.Original
	End With
	With cmdUpdate.Parameters.Add("@p3", DbType.Int32)
		.SourceColumn = "idPoint"
		.SourceVersion = DataRowVersion.Original
	End With
	adapter.UpdateCommand = cmdUpdate
	' update the distance to the database
	Try
		adapter.Update(pointsSet, "Point")
	Catch ex As DBConcurrencyException
		MessageBox.Show(ex.Message, "Distance calculation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
		Exit Sub
	Finally
		pointsSet = Nothing
		adapter = Nothing
	End Try
End Sub
Merci d'avance,
Thibaut.