Databases - Page 3 | ||||
Part 4 - Editing/Updating Records | ||
NOTE: You can drag and drop or copy and paste the blocks of code below into the code editing area of the appropriate button events. Put this code in the Edit Record button''s Action event: Put this code in the Update Record button: //a cursor "points at" a particular record theSQL = "select " cur = db.SQLSelect(theSQL)//get the record to update cur.IdxField(1).setString (firstField.text)//update firstName cur.Update//do the update iif db.error then cur.close | ||
The code in the Edit Record button makes it possible to edit the data in the Data Browser window's fields. It also enables the Update Record button so that changes to the data can be saved. The code in the Update Record is mostly SQL. Basically, it tells the database "SimpleDB" to update changes to the record in the "People" table identified by the number in idField's text. Once this code for the Edit Record and Update Record buttons has been entered, users can edit records by first clicking the Edit Record button to allow editing in the data fields and then, once editing is completed, clicking the Update Record button to save the changes made to the record's data. | ||
Part 5 - Deleting Records | ||
Put this code in the Delete Record button''s Action event: //a cursor "points at" a particular record iif idField.text <> "" then This code tells the database to delete the record from the table "People" where the ID field (in the record) has the number entered in idField on the window. | ||