A agricult Member Licensed User Jan 26, 2020 #1 Hello, I have very little VB programming experience from 30 years ago but still managed to make good use of the great B4X. My problems start when I want to do things "nicer" or shorter. I tried to check if a database string field in a resultset is empty and found the If NOT (rs.GetString("Litter")= NULL) THEN option in the forum but that doesn't work for me (using IF rs.GetString("Litter")="" doesn't work either), I can work around it by always using e.g."-" for an empty field in the DB but being able to check would be easier. Code: Copy If Not (rs.GetString("Litter")=Null) Then lbllitter.Text=xx.GetString("Littersize") End If If somebody is willing to give me a hint why it doesn't work that way, thank you very much in advance.
Hello, I have very little VB programming experience from 30 years ago but still managed to make good use of the great B4X. My problems start when I want to do things "nicer" or shorter. I tried to check if a database string field in a resultset is empty and found the If NOT (rs.GetString("Litter")= NULL) THEN option in the forum but that doesn't work for me (using IF rs.GetString("Litter")="" doesn't work either), I can work around it by always using e.g."-" for an empty field in the DB but being able to check would be easier. Code: Copy If Not (rs.GetString("Litter")=Null) Then lbllitter.Text=xx.GetString("Littersize") End If If somebody is willing to give me a hint why it doesn't work that way, thank you very much in advance.
aeric Expert Licensed User Longtime User Jan 26, 2020 #2 How about? Code: Copy If rs.GetString("Litter") <> “” Then lblLitter.Text = rs.GetString("Litter") End If Upvote 0
How about? Code: Copy If rs.GetString("Litter") <> “” Then lblLitter.Text = rs.GetString("Litter") End If
Erel B4X founder Staff member Licensed User Longtime User Jan 26, 2020 #3 What do you mean with empty? Is the value 'null' in the database? Upvote 0
A agricult Member Licensed User Jan 26, 2020 #4 aeric said: How about? Code: Copy If rs.GetString("Litter") <> “” Then lblLitter.Text = rs.GetString("Litter") End If Click to expand... Interesting, this seems to work, I will test it a bit more later today, thank you very much for your answer. Upvote 0
aeric said: How about? Code: Copy If rs.GetString("Litter") <> “” Then lblLitter.Text = rs.GetString("Litter") End If Click to expand... Interesting, this seems to work, I will test it a bit more later today, thank you very much for your answer.
A agricult Member Licensed User Jan 26, 2020 #5 Erel said: What do you mean with empty? Is the value 'null' in the database? Click to expand... I created the DB structure with "DB Browser for SQLite", where I also added my testdata. On start the empty fields show NULL but once I added and deleted data in a field it shows "nothing" not even NULL Upvote 0
Erel said: What do you mean with empty? Is the value 'null' in the database? Click to expand... I created the DB structure with "DB Browser for SQLite", where I also added my testdata. On start the empty fields show NULL but once I added and deleted data in a field it shows "nothing" not even NULL
Erel B4X founder Staff member Licensed User Longtime User Jan 26, 2020 #6 Nulls and strings are a bad combination. You can use ifnull in the query to convert db null values to empty strings: https://www.b4x.com/android/forum/t...lue-returned-from-database.105706/post-661903 Then compare the result to "". Upvote 0
Nulls and strings are a bad combination. You can use ifnull in the query to convert db null values to empty strings: https://www.b4x.com/android/forum/t...lue-returned-from-database.105706/post-661903 Then compare the result to "".