Recent

Author Topic: [Solved] Filling TCombobox from a SQLite3 database  (Read 1833 times)

rickielynn

  • New Member
  • *
  • Posts: 18
[Solved] Filling TCombobox from a SQLite3 database
« on: January 08, 2018, 06:58:23 pm »
I've saved some data into a STRING field of an SQLite3 database.  Then I retrieve that data with a SELECT DISTINCT statement to fill a TCombobox.   All works well until the first data is a number, like 105, then the TCombobox fills with all zeros, even though 105 was saved to the database as a string.   

I've tried testing the data with IsNumber(), then converting it to a string with IntToStr before sending it to the TCombobox, but haven't gotten IsNumber to work yet.  But it seems the data should already be a string anyway.

Update 1: The problem doesn't seem to be with the TCombobox because I can display the first record, 105, in a TLabel.Caption indicating it is indeed a string, but when I try to display the second record, which is alpha, in TLabel.Caption it displays a 0.

Update 2:  If I change the datatype in the database to Char or Text, it works.  Numbers will fill TCombobox as well as alpha.  Which is best to use, since I want to be able to store numbers as well as alphanumeric characters.

« Last Edit: January 08, 2018, 10:10:47 pm by rickielynn »

Handoko

  • Hero Member
  • *****
  • Posts: 5154
  • My goal: build my own game engine using Lazarus
Re: Filling TCombobox from a SQLite3 database
« Reply #1 on: January 08, 2018, 07:26:04 pm »
Bugs can happen anywhere in the source code. Without inspecting the code, we can't be sure to say where you did wrong.

Please copy all the necessary files including the database into a new folder, excluding the lib folder, binary (*.exe) and bak files. Compress the folder and send the zip file to the forum. If for some reasons you're not willing to publicize the code, you can write a demo sample showing that issue.

GAN

  • Sr. Member
  • ****
  • Posts: 370
Re: Filling TCombobox from a SQLite3 database
« Reply #2 on: January 08, 2018, 09:53:28 pm »
In SQlite if you don't define a default value to a column, then it's null, may be this. But as @Handoko saids, show the code and the table.
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

rickielynn

  • New Member
  • *
  • Posts: 18
Re: Filling TCombobox from a SQLite3 database
« Reply #3 on: January 08, 2018, 10:10:14 pm »
Thanks, guys.  I didn't publish any code because I think the problem is in SQLite3.  I changed the records from type STRING to type TEXT in SQLite3 and the problem went away.

 

TinyPortal © 2005-2018