Android Question Querying SQLite DB - makes no sense!

rbw152

Member
Licensed User
Longtime User
Hi all

here's a small piece of code:

Sub DisplayAsset (aid)

Dim sql As String, sqlret As String

sql = "SELECT ID, AssetID, Type FROM assets WHERE AssetID ='" & aid & "'"
Command.CommandText = sql

'Initiate Data Reader
Datareader.New1
Datareader.Value = Command.ExecuteReader

sqlret = Datareader.GetValue(2)
Datareader.Close
End Sub

The first time this code runs it returns one record containing the asset or item we're looking for (and we can see this in the sqlret variable). If I then execute the same code again, either using the same asset id or another one, it returns nothing!

If I run the code with a simple SELECT * query it returns all records correctly no matter how many times we run it.

What is going on? It's driving me and a colleague nuts here.

Thanks!
 

eps

Expert
Licensed User
Longtime User
Can you place the code with the [ code ] and [ / code ] delimiters, it will make it a lot easier to read.

The only thing I can think of is to msgbox or toastmessageshow the aid variable before executing the SQL, this has probably changed and therefore doesn't match any of the rows.. You would be able to tell really quickly if it is the case, by seeing what the variable is before executing the SQL.
 
Upvote 0

rbw152

Member
Licensed User
Longtime User
Can you place the code with the [ code ] and [ / code ] delimiters, it will make it a lot easier to read.

The only thing I can think of is to msgbox or toastmessageshow the aid variable before executing the SQL, this has probably changed and therefore doesn't match any of the rows.. You would be able to tell really quickly if it is the case, by seeing what the variable is before executing the SQL.

Actually you were close with your answer. We've fixed it now but on closer inspection we found there were hidden characters in the 'aid' variable the second time we ran the sub. We couldn't see these in a message box we used to display its value so it had us baffled for a while. The problem arose earlier on in the program and we were looking in the wrong place.

Anyway, thanks very much for your reply!
 
Upvote 0
Top