I am new to powerbuilder and having a lot of trouble using datawindows. I can't get my head around the insert mechanism of it. Can someone explain it to me, or at least point me in the right direction(article, tips etc...) ?
The SQL generated by the DataWindow is controlled by the Update Properties (menu item Rows / Update Properties...). From there, you can select a single table and set the properties that it will use to generate the SQL. Where Clause... determines which columns and their original values are used in the WHERE clause for UPDATEs and DELETEs. Key modification only comes into play when you change (or allow the user to change) columns that you've defined as key. Updatable Columns is the list of what will generate SQL (this doesn't affect what the UI allows one way or the other). Key columns can be the Primary key (which can be auto-populated with the Primary Key button, if you're DBMS supports the calls to query that from the database), but it doesn't have to be. (There are fairly unique cases where you might want to do something different.) If you've got an identity column as your key, you can identify that to your DataWindow and it will retrieve the generated value after an INSERT.
After that, populating the data in the DataWindow with InsertRow(), DeleteRow(), SetItem() and, of course, letting the user at the UI, will be changing data and status flags that will determine the SQL generated when Update() is called.
All these can be changed at run time with the Modify() function, so you can do things like update multiple tables with one DataWindow. This is implemented in PowerBuilder Foundation Class's multi-table update service, so if you ever want to change these values at run time, that's some good sample code.
Good luck,
Terry.
@Archangel You still need to provide the test_id field when inserting the row into the datawindow even after you specified a value for it as a retrieval argument. After you do your insertrow, make sure you do a setitem for all values which do not allow null values.