DatabaseField

From Xojo Documentation
Jump to: navigation, search

Class (inherits from Object)

Used to access the values of fields in a record in a database table.


Properties
BooleanValue Int64Value PictureValue
CurrencyValue IntegerValue StringValue
DateValue Name ReadOnlyProperty.png Value
DoubleValue NativeValue ReadOnlyProperty.png


Methods
GetString SetString


Notes

Assignments to the DateValue property store the time as well as the date, as with DatabaseRecords. When getting a value, the resulting Date object may contain a time as well as a date. For fields of type Date, the time will be 00:00:00 (midnight); and for fields of type Time, the date will be January 1, 0001. Fields of type TimeStamp contain valid data for both the date and time.

Boolean fields are strict about what they expect when using the BooleanValue function: "0" and "False" are treated as False and "1" and "True" are treated as True. The behavior of any other values is undefined when retrieved using BooleanValue. The StringValue property, on the other hand, should be able to retrieve the original data if it can't be identified as a Boolean.

The conversion operator, Operator_Convert, has been added to StringValue, BooleanValue, DateValue, IntegerValue, and DoubleValue.

Examples

The following method populates a ListBox with a RecordSet. It uses the Name and StringValue properties to obtain the fieldnames and values:

Sub PopulateListBox(dataList As Listbox, rs As RecordSet)
If rs Is Nil Then Return

// set up listbox state for population
dataList.DeleteAllRows
dataList.Columncount = rs.Fieldcount

// Add the DB columns as the heades for the ListBox
dataList.ColumnCount = rs.FieldCount
dataList.Column(-1).WidthExpression = "100"
For i As Integer = 0 To rs.FieldCount-1
dataList.Heading(i) = rs.IdxField(i+1).Name
Next

// Add the data from the table
While Not rs.EOF
dataList.AddRow("")

For i As Integer = 0 To rs.FieldCount-1
dataList.Cell(dataList.LastIndex, i) = rs.IdxField(i+1).StringValue
Next

rs.MoveNext
Wend
End Sub


The following example uses the Value property to set the values of fields of different data types.

Dim myDB As RealSQLDatabase
Dim rs As RecordSet
rs = myDB.SQLSelect("SELECT * FROM MyTable")
rs.Edit
rs.Field("MyName").Value = Nil // NULL this field, does not work for all database plugins
rs.Field("MyID").Value = 23
rs.Field("MyText").Value = "Test"
rs.Update
If Not myDB.Error Then
myDB.Commit
Else
MsgBox("Error: " + myDB.ErrorMessage)
End If

See Also

Database, DatabaseRecord, RecordSet classes.

Personal tools
Namespaces

Variants
Actions
Main
Content
Starting Out
Dig Deeper
More Help
Toolbox
About