Android Question Updating a SQLite Data Base

Terradrones

Active Member
Hi All, I can add and erase Coordinate Points from a Database, but am baffled why my coding to update a Coordinate is not working. I do not use the "ID", but rather the name of the Coordinate Point. Herewith my Code:

Sub StoreCoords
If CoordName.Text<>"" Then
SelectCoordType
ResultSet =CGlobals.SQL1.ExecQuery2(Query, Array As String (CoordName.Text))
If ResultSet.NextRow = True Then
'if it exists show a message and do nothing else
Msgbox2Async("Override?", "Coord Exists", "Yes", "No", "", Null,False)
Wait For Msgbox_Result (Answ As Int)
If Answ = DialogResponse.POSITIVE Then 'if yes, delete the entry
AmendCoord
Else
CoordName.RequestFocus
Return
End If
Else
'if not, add the Coord
If CGlobals.CoordCode=1 Then
'Site Coords
Query = "INSERT INTO SCoords VALUES (?,?,?,?,?)"
else if CGlobals.CoordCode=2 Then
'Global Coords
Query = "INSERT INTO GCoords VALUES (?,?,?,?,?)"
Else
'Job Coords
Query = "INSERT INTO Coords VALUES (?,?,?,?,?)"
End If
CGlobals.SQL1.ExecNonQuery2(Query, Array As String(CoordName.Text, CoordEast.Text, CoordNorth.Text,Elevation.Text,CoordDescription.text))
ToastMessageShow("Coord Added", False)
End If
Else
Msgbox2Async("Not Enough Data Entered", "Missing Data", "OK", "", "", Null,False)
Return
End If
ResultSet.Close
End Sub

Here I want to save a Point, but the program first checks if the Point exists and if so, the program goes to the following routine and should update the info about the point:

Sub AmendCoord
'Main.SQL1.ExecNonQuery2("UPDATE TKRecordTemp SET Sent=?, Success=? WHERE OSID = ?",Array As String(1,1,1231234105))?
If CGlobals.CoordCode=1 Then
'Site Coords
Query = "UPDATE SCoords Set Name = ?, East = ?, North = ?, Elevation = ?, Description = ? WHERE Name = ? "
else if CGlobals.CoordCode=2 Then
'Global Coords
Query = "UPDATE GCoords Set Name = ?, East = ?, North = ?, Elevation = ?, Description = ? WHERE Name = ?"
Else
'Job Coords
Query = "UPDATE Coords Set East = ?, North = ?, Elevation = ?, Description = ? WHERE Name = ?"
End If
CGlobals.SQL1.ExecNonQuery2(Query, Array As String(CoordName.Text, CoordEast.Text,CoordNorth.Text,Elevation.Text,CoordDescription.text))
ToastMessageShow("Entry Updated", False) 'display a confirmation message
End Sub
 

Mahares

Expert
Licensed User
Longtime User
but am baffled why my coding to update a Coordinate is not working
If you look carefully at the Sub AmendCoord, two of the UPDATe syntax query variables have 6 parameters and one has 5. You are not matching for the ExecNonQuery2( which has 5 elements in the array to work properly. I don;t think your problem is difficult, but you need to write your code enclosed in code tags, because it is hard to follow. In addtion, if you can put a small project together and attach it to a post, it will be easier to see the problem.
 
Upvote 0
Top