Query Binding to a custom parameter in a view

I have defined a custom property in a view (say taskdata) which I bind to an SQL Query returning a row from a database in a say [0x8] dataset for single row of data. Now I want to bind text property of 8 different labels on the view to the individual cells of the row dataset. How to do that?

The property binding shows that it is a dataset correctly, as shown in the image below, but how to access its individual cells while binding to label’s text property? (I tried putting suffix [0,1] in obviously vain!)

If your dataset is [0x8] that means it’s empty :X

When you get your query working, you can access a cell from a row quite easily with an expression binding: {view.custom.dataset}[x] where x is the 0-based index of the row.


Not really! Here is the binding without the index, which shows the result as a data set [0x8] However assigning index [1] to it gives binding error! - see second screen shot. I even tried [0,1] but same error

Yes, because your dataset is empty.

If you need to handle empty datasets:


This will return the cell at index x if the dataset is not empty, and null if it’s empty.


But when does the query get executed to initialize the custom property in the view? When the View is displayed or any other event?

If it’s a query binding, it should execute periodically based on the query’s poll rate. I think.

The binding’s poll rate.

In design it should run when you apply any changes, to that binding.

Personally I’m a fan of doing it the pythonic way - try first, ask forgivness later. Also makes it so you don’t have to check the length.



In the designer go to the Property Editor and inspect view.custom.taskdata. I think you’ll find that it is empty.

Fix your query so that some data shows up here and then your label bindings should work.

The table was empty though the headers are correctly filled. I found the problem; the query has an input field which comes from a parameter coming from the parent view of the view. Default value of this input field was left blank, so the query was returning null ! On giving an initial value it initializes the table and the binding to label text should work now! Thanks a lot all.

However the original question remains, when query return null, whats the best way to access the individual elements of the data set having null value!

My first problem is solved as explained above. It definitely executes the query for the first time while binding. However not sure when does it update by default when execution rate is not defined in the binding window. My guess is by default it will execute only when the view is loaded, unless specified an execution rate in the window in which it will execute periodically as you mentioned. Which makes sense actually.

Yes works fine! Thanks!

This also works fine! Thanks!

Didn’t know this existed. I really should study expressions a bit more…

1 Like

It’s a very nice and more succint technique I learned from @pturmel. I use it a lot for add/edit windows. For a text box for instance, I put a custom property I tend to call initialValue and bind that to try({Root Container.initialData}[0, 'someColumn'], 'DEFAULT VALUE FOR CREATE'). Then I would bind my text property to the initialValue property and now I have set up the text box for loading a record and provided what should be in the text box for a new record in a single expression.

1 Like

perhaps it may be computationally more efficient as well than checking the length of the dataset!

1 Like

How do I just check the output of the a dataset for null?
My label shows as "[]"

Check that the number of rows in greater than 0

if  not ds.rowCount:
    #do work with dataset


if not ds.rowCount == 0:
    #do work with dataset

If you prefer, either will work.

1 Like

I didn’t ask my question right. I set the output as scalar, then it told me the output was null from the query. However, your answer got me the solution.
if not value: