[Gambas-user] DataView Help

Gianluigi gradobag at gradobag.it
Tue Jul 11 14:40:29 CEST 2023


Il 11/07/23 14:31, T Lee Davidson ha scritto:
> On 7/11/23 07:53, Benoit Minisini wrote:
>> Otherwise, you can use the DataView.Find() method to move the view to 
>> a specific record from a SQL where clause. It's easy if you know the 
>> primary keys of the record you just have created.
>
> Gianluigi,
>
> The `students` table has no columns set as unique and the only primary 
> key is `students_id` which is not available until after the record is 
> saved.
>
> To have a high confidence of finding the very record that was just 
> saved, you will need a record signature that is as unique as possible. 
> The only way I can think to come close to that is to construct a 
> 'where' clause using all the available field values (which does not 
> include `students_id`), save it to a global variable in the 
> DataSource.BeforeSave event handler, and then use it with Find after 
> DataSource.Save.
>
>

Hi Lee,

Getting the identity of the added student is easy, in the Save Sub just 
type:

   Dim sSQL As String = "SELECT MAX(students_id) FROM students;"
   Dim i As Integer

   DataSource1.Save
   i = DataSource1.Connection.Exec(sSQL)[0]
   Print "STUDENT ID = "; i

I still couldn't select the correct row though, I always end up 
selecting the last one

Regards

Gianluigi



More information about the User mailing list