1. Wolfgang Schwarz
  2. Valentina Database ADK
  3. Montag, März 19 2018, 01:16 PM
  4.  Abonnieren via E-Mail
I have found two ways to fill in Xojo a listbox with records of Valentina-DB. Is this way right, and which is the best?

Way 1:

Dim tblPerson As VTable
Dim bRes As Boolean
Dim i As Integer

tblPerson = mDatabase.Table("Person")


bres = tblPerson.FirstRecord
For i = 1 To tblPerson.RecordCount
lbPerson.AddRow(tblPerson.Field("FirstName").GetString, tblPerson.Field("LastName").GetString)
lbPerson.RowTag(lbPerson.LastIndex) = tblPerson.ULongField("RecID").Value
bres = tblPerson.NextRecord

Way 2:

Dim cur As VCursor
Dim i As Integer

cur = mDatabase.SqlSelect("SELECT * FROM Person")


For i = 1 To cur.RecordCount
cur.Position = i
lbPerson.AddRow(cur.Field("FirstName").GetString, cur.Field("LastName").GetString)
'lbPerson.RowTag(lbPerson.LastIndex) = cur.ULongField("RecID").Value // doesn´t work

However, how can I get RecID from VCursor? With the above method I get an exception
There are no comments made yet.
Ruslan Zasukhin Akzeptierte Antwort
Hi Wolfgang,

Way 1 - uses VTable class -- this is what we name API way.
it is okay for local dbs.

Way 2 - uses SQL and VCursor as result of the SELECT command.
it is better if you work with remote VServer.
SQL Way also is okay for LOCAL db of course. And if you know SQL then why not use its power?

To get RecID field in SQL, you should specify it in the SELECT

There are no comments made yet.
Wolfgang Schwarz Akzeptierte Antwort
Thanks Ruslan
There are no comments made yet.
Scott Akzeptierte Antwort
One side note on listboxes and VDB.

I also used the RecID field as the rowtag in a Xojo listbox. I quickly had issues with data consistency because the RecID field is not a permanent identifier for data. A RecID can be reused when a record is deleted and new data is inserted into the DB.

For example, after you populate the listbox with the records you want (using the RecID as the rowtag), this data now becomes stale. If another user deletes, let's say record 5 (RecID 5), and you click on the listbox with the rowtag of (RecID) 5 - any DB operations you perform with that RecID will be on the wrong data.

I found it safer to place a ULLONG field in tables were I needed permanency and use either a Serial32 or Serial64 (which is basically a sequence) to generate a unique identifier for each record. I also set this field's "Unique" attribute to true. I retrieve both RecID and sequence number from the DB when populating a listbox and place one field in the rowtag and one in a column with a width of 0 making it invisible. Which one goes where is up to you and your programming style. The Xojo rowtag can also take an array if you want to get creative and put both the RecID and the sequence # in the rowtag.

Before I complete any record operations, i check the DB to see if the sequence # still exists and if so, does the RecID match. If true, the record still exits and I use a server side cursor to lock the record while I perform whatever operation needs to happen.

If the sequence number doesn't exist, the record was deleted before I refreshed my listbox. This is just a basic method. There are many ways to do this as Ruslan or Ivan can tell you.
There are no comments made yet.
  • Seite :
  • 1

There are no replies made for this post yet.
However, you are not allowed to reply to this post.


Announcements & News
  1. 0 subcategories
Valentina Studio
  1. 2 subcategories
Valentina Server
  1. 4 subcategories
Valentina Database ADK
  1. 0 subcategories
Valentina Reports ADK
  1. 0 subcategories
Other Discussions
  1. 2 subcategories
BETA Testing
  1. 0 subcategories
Education & Research
  1. 0 subcategories