Show: Delphi C++
Display Preferences

Accessing Field Values with a Dataset's FieldByName Method

From RAD Studio
Jump to: navigation, search

Go Up to Working with field components Index

You can access the value of a field with a dataset's FieldByName method. This method is useful when you know the name of the field you want to access, but do not have access to the underlying table at design time.

To use FieldByName, you must know the dataset and name of the field you want to access. You pass the field's name as an argument to the method. To access or change the field's value, convert the result with the appropriate field component conversion property, such as AsString or AsInteger. For example, the following statement assigns the value of the CustNo field in the Customers dataset to an edit control:

Edit2.Text := Customers.FieldByName('CustNo').AsString;
Edit2->Text = Customers->FieldByName("CustNo")->AsString;

Conversely, you can assign a value to a field:

begin
  Customers.Edit;
  Customers.FieldByName('CustNo').AsString := Edit2.Text;
  Customers.Post;
end;
Customers->Edit();
Customers->FieldByName("CustNo")->AsString = Edit2->Text;
Customers->Post();

See Also

Personal tools
In other languages