[Gambas-user] DataView Help
Gianluigi
gradobag at gradobag.it
Tue Jul 11 15:15:53 CEST 2023
Il 11/07/23 14:52, Benoit Minisini ha scritto:
> Le 11/07/2023 à 14:40, Gianluigi a écrit :
>>
>> 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
>>
>
> If your record primary key is a serial field, you can use the
> 'LastInsertId' property of the 'Connection' object to get it.
>
> Regards,
>
Hi Benoit,
'LastInsertId' I hadn't noticed it cool, unfortunately I keep bumping up
against my miserable brain, this is what I tried without being able to
select the correct line:
Public Sub btnSave_Click()
' Dim sSQL As String = "SELECT MAX(students_id) FROM students;"
Dim i As Integer
DataSource1.Save
' i = DataSource1.Connection.Exec(sSQL)[0]
i = DataSource1.Connection.LastInsertId
Print "STUDENT ID = "; i
' $iCurrentIndex = DataSource1.Find("students_id=&1", i)
' Print $iCurrentIndex
DataView1.Find("students_id=&1", i)
'Try DataView1.View.Rows[DataView1.View.Row].Selected = True
End
Sorry and regards
Gianluigi
More information about the User
mailing list