RAD Studio |  |

Accessing Field Values with a Dataset's FieldByName Method
See Also
Collapse All

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:

Copy Code

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

Copy Code

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

Conversely, you can assign a value to a field:

Copy Code

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

Copy Code

    Customers->Edit();
    Customers->FieldByName("CustNo")->AsString = Edit2->Text;
    Customers->Post();

See Also

Displaying Field Component Values in Standard Controls

Accessing Field Values with a Dataset's Fields Property

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!