Share via


Retrieving a row

Retrieving a row from a table is a multi-step process. First, you must decide which key you want to use to retrieve the row. Use the Table Descriptions window in Microsoft Dynamics GP to view the keys and each key's components. Specify the key to use, and then set the values of the key fields. Finally, use the Get() or Change() method for the table to retrieve the record. Which you use depends on whether you want to lock the record. You will learn more about locking in Row locking.

The following C# example retrieves the row for the customer American Electrical Contractor from the RM_Customer_MSTR table. The second key of the RM_Customer_MSTR table is used. This key contains one component, the Customer Name. The contact person for the retrieved customer is displayed in a dialog.

// Variable for any table operation error
TableError err;

// Create a reference to the table
RmCustomerMstrTable CustomerMasterTable;
CustomerMasterTable = Dynamics.Tables.RmCustomerMstr;

// Set the key to use for the table
// Key 2 - Contains the Customer Name
CustomerMasterTable.Key = 2;

// Set the value for the key columns
CustomerMasterTable.CustomerName.Value = "American Electrical Contractor";

// Retrieve the row
err = CustomerMasterTable.Get();

if (err == TableError.NoError)
{
    MessageBox.Show(CustomerMasterTable.ContactPerson.Value);
}
else
{
    // Display the error that occurred
    MessageBox.Show(err.ToString());
}
// Close the table
CustomerMasterTable.Close();