datacontrolpropaSet the properties for DataControl1 as shown here.

Doing this tells DataControl1 to use the database called “SimpleDB” and to use the table called “People” within that database. The SQLQuery tells it what set of records to get from the database. In this case we are asking for all of the records of the table “People”.

fieldbehaviouraSet the DataScource property for ALL 4FIELDS to DataControl1

Set the DataField properties as follows:
idField = ID
firstField = firstName
lastField = lastName
emailField = emailAddress

Now the fields are connected to DataControl1 and DataControl1 is connected to the “People” table in the “SimpleDB” database. Also, each field on the window is connected to a corresponding field in the “People” table.

When DataControl1 runs its query “select * from People” if will put the data from the first record into the appropriate fields.
(The * in the query statement means “all records”)

Part 3 – Adding records to the database

We now need to add a data input window. Add a new window to your project and call it “addRecordWindow”.newrecordpica

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.

Add controls to the window as shown here.

In the Save button’s Action event put this code:

dim r as databaserecord
//db is a global property in Module1; it’s initialized in the app class’s Open event

r = new databaserecord//create a new record
r.column(
“firstName”) = firstField.text//stored as a string
r.column(
“lastName”) = lastField.text//stored as a string
r.column(
“emailAddress”) = emailField.text//stored as a string
r.integercolumn(
“ID”) = val(idField.text)//stored as an integer 

|db.insertRecord “People”,r //add the new record to the database

if db.error then
msgBox db.errormessage
end if

dataBrowserWindow.dataControl1.runQuery//update dataControl1

self.close

In the Cancel button’s Action event put:
self.close

To see the magic of DataControl1 at work we need to add some records to our empty database.

Run the project and click the New Record button. In the data entry sheet enter “1” in the ID field and some appropriate data in the other 3 fields. Click save.

The data you just entered should be visible in the Data Browser window.

Add at least 2 more records making sure to put a unique number in the ID field for each record.

Now you can use the back and forth arrows of the DataControl to browse the records you have created.

All of this was accomplished without a single line of code. It was all done by setting properties for the DataControl and the Fields.

Next page