Question, data show a record of sqlite

marbellapc

Member
Licensed User
Longtime User
The problem is that I have created in sqlite3 db, works well in the ListView shows me the records with the product name, but when I click on a record, I always display them last data record in the list when I click on the ListView.
B4X:
Sub ListView1_ItemClick (Position As Int, Value As Object)
   RemoveViews
   Activity.LoadLayout("Product")
   ItemSelected = Value
   
   Label_Titulo.Text         = Cur.GetString("Titulo")
   Label_Fecha.Text          = Cur.GetString("Fecha")
   ImageView_Foto.Bitmap     = LoadBitmap(File.DirAssets, Cur.GetString("Imagen")) ' Pruebas de imagen
   Label_Producto.Text       = Cur.GetString("Producto")
   Label_Localidad.Text      = Cur.GetString("Localidad")

    End Sub
I changed several times how to do the query but without success, keeps giving the data of the last record of the list of ListView.
B4X:
Sub ListView1_ItemClick (Position As Int, Value As Object)
   RemoveViews
   Activity.LoadLayout("Product")
   ItemSelected = Value

    Cur = SQL1.ExecQuery("SELECT Titulo, Imagen, Localidad, Producto, Fecha, Ingredientes, Proceso FROM Countries")
 For i = 0 To Cur.RowCount - 1
    Cur.Position = i
   Label_Titulo.Text         = Cur.GetString("Titulo")
    Label_Fecha.Text         = Cur.GetString("Fecha")
   ImageView_Foto.Bitmap     = LoadBitmap(File.DirAssets, Cur.GetString("Imagen"))
   Label_Producto.Text       = Cur.GetString("Producto")
   Label_Localidad.Text      = Cur.GetString("Localidad")
 Next
'    Cur.Close
End Sub
I have relied on the example of jpvniekerk, but can not get the labels show the data for the record down.
http://www.b4x.com/forum/basic4andr...arebones-view-examples-sqlite.html#post120915

I hope you can help me out and guide me in what I'm doing wrong.

Greetings and thanks in advance
 

Attachments

  • Cometelo.zip
    59.1 KB · Views: 258

mc73

Well-Known Member
Licensed User
Longtime User
Why see you looping inside the click? You should set the cursor position to the selected ID and get its data. Haven't checked your code, so please disregard my message if what I saw was just 'bad' copy-paste.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Replace this line:
B4X:
Cur = SQL1.ExecQuery("SELECT Titulo, Imagen, Localidad, Producto, Fecha, Ingredientes, Proceso FROM Countries"

with this line: You will be good to go.
B4X:
Cur = SQL1.ExecQuery("SELECT Titulo, Imagen, Localidad, Producto, Fecha, Ingredientes, Proceso FROM Countries" _
   & " WHERE Titulo= '" & ItemSelected & "'" )
 
Upvote 0

marbellapc

Member
Licensed User
Longtime User
Klaus, the database is within the zip file if File folder.

Mahares, perfect, I had not thought of that, had tested
B4X:
Cur = SQL1.ExecQuery("SELECT Titulo, Imagen, Localidad, Producto, Fecha, Ingredientes, Proceso FROM Countries WHERE ID= " & ItemSelected)
And kept giving clear error, but change it so I've put, wow, perfect.

Thank you very much to all, you are the best, and you are always there for newbies like me, Greetings

and again thank you very much
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Hi marbellapc,

Sorry, I expected finding the database in the Files Tab in the IDE.
I didn't look in the Files directory.

I played a bit with your program, below some comments:
You can repalce these lines
SQLText = "SELECT * FROM Countries ORDER by Titulo"
by this.
SQLText = "SELECT Titulo FROM Countries ORDER by Titulo"
As you display only the Titulo column no need to read all the rest.

Here you can replace
Cur = SQL1.ExecQuery("SELECT Titulo, Imagen, Localidad, Producto, Fecha, Ingredientes, Proceso FROM ...
by
Cur = SQL1.ExecQuery("SELECT * FROM ...
because you read all columns.

Attached the modified version.

Best regards.
 

Attachments

  • Cometelo1.zip
    15.4 KB · Views: 248
Upvote 0

marbellapc

Member
Licensed User
Longtime User
Hello Klaus,
You're absolutely right, I have to change sqlite statements and further optimize the code to leave cleaner.

I focused on how to display the records and pay no attention to those details.

best Regards

And thank you very much for your advice and help
 
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
I'd like to add a photo to DB
which is taken from Tablet Cam. which type should ı use ? text/blob/ .. . and how could ı take the photos from device after took a photo ?????
 
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
Yes
thank you, but ı have trauble .Is that possible to send to my Table in my PERSON DB ? and read from it again
 
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
I mean
yes it works but
I want to make one program
and after took picture
, is that the same for sending Table Database

upload_2014-2-24_16-35-36.png



upload_2014-2-24_16-36-28.png
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I have never done this either, so I could give you only the principles.

As I don't know how you want to manage the database it's difficult to give concrete advices.
What is edtImage ?
If I understand your sketch, it's an edit screen where you should display the image if there exist one in the database.
With the button you can take an image and with another button update the database.
 
Upvote 0
Top