Hello,
I was wondering if it is possible to execute an UPDATE SQL query within a data reader object? For example, would it be possible to make the code below work. Clearly at the moment this generates an error saying that there is already an open data set associated with this connection.
Do While myReader2.Read()
lat2 = myReader2("lat").ToString()
lon2 = myReader2("lng").ToString()
unit = "M"
Dim return_distance As String = distance(lat1, lon1, lat2, lon2, unit)
If return_distance.length <> 1 Then
trimmed_distance = return_distance.SubString(0,4)
Else
trimmed_distance = return_distance
End If
Dim converted_distance As Integer
converted_distance = CInt(trimmed_distance)
Dim outcode As String
If trimmed_distance <= 30 Then
postcode_match.Add(myReader2("outcode").ToString())
Dim strSQL As String = "UPDATE tbl_sales SET distance_temp = '" & trimmed_distance & "' WHERE PostCode LIKE '%" & myReader2("outcode").ToString() & "%'"
myCommand.Connection = conn
myCommand.CommandText = strSQL
myCommand.ExecuteNonQuery()
distance_list.Add(trimmed_distance)
End If
Loop
myReader2.Close()
I was wondering if it is possible to execute an UPDATE SQL query within a data reader object? For example, would it be possible to make the code below work. Clearly at the moment this generates an error saying that there is already an open data set associated with this connection.
Do While myReader2.Read()
lat2 = myReader2("lat").ToString()
lon2 = myReader2("lng").ToString()
unit = "M"
Dim return_distance As String = distance(lat1, lon1, lat2, lon2, unit)
If return_distance.length <> 1 Then
trimmed_distance = return_distance.SubString(0,4)
Else
trimmed_distance = return_distance
End If
Dim converted_distance As Integer
converted_distance = CInt(trimmed_distance)
Dim outcode As String
If trimmed_distance <= 30 Then
postcode_match.Add(myReader2("outcode").ToString())
Dim strSQL As String = "UPDATE tbl_sales SET distance_temp = '" & trimmed_distance & "' WHERE PostCode LIKE '%" & myReader2("outcode").ToString() & "%'"
myCommand.Connection = conn
myCommand.CommandText = strSQL
myCommand.ExecuteNonQuery()
distance_list.Add(trimmed_distance)
End If
Loop
myReader2.Close()