Retrieve Records with Primary, Non-Primary, and Composite Keys

Updated May 11, 2010
Iron Speed Designer V7.0 and later

Retrieving records with primary key using the GetRecord() function

It’s easy to read a single record from the database using a primary key with the GetRecord() function:

C#:

OrdersRecord myRecord;

string whereStr = "OrderID='10261'";

myRecord = OrdersTable.GetRecord(whereStr);

Or

OrdersRecord myRecord;

myRecord = OrdersTable.Instance.GetRecord("10261", false);

Visual Basic .NET:

Dim myRecord As OrdersRecord

Dim whereStr As String = "OrderID='10261'"

myRecord = OrdersTable.GetRecord(whereStr)

The argument to the GetRecord specifies a whereStr.

Visual Basic .NET:

Dim myRecord As OrdersRecord

myRecord = OrdersTable.GetRecord("10261", False)

The first argument to GetRecord specifies the primary key value as a string.  Set the second argument to True if you intend to update the contents of this record so it can be saved in the database later.  Set the second argument to False to fetch a read-only record.

Retrieving records using a non-primary key

The GetRecord function also returns the record based on a non-primary key.

C#

OrdersRecord myRecord;

string whereStr= "EmployeeID='1'";

myRecord = OrdersTable.GetRecord(whereStr);

Visual Basic .NET:

Dim myRecord As OrdersRecord

Dim whereStr As String = "EmployeeID='1'"

myRecord = OrdersTable.GetRecord(whereStr)

Retrieving records using a composite key

Use the GetRecord function to retrieve records with a composite key, just like retrieving a record with a primary key.  However, pass a KeyValue composite key structure as an argument to GetRecord instead of a simple primary key string.  After defining (declaring) the KeyValue object, add elements to the KeyValue object using the KeyValue.AddElement() method.

C#

BaseClasses.Data.KeyValue myKeyValue= new BaseClasses.Data.KeyValue();

myKeyValue.AddElement(Order_DetailsTable.Instance.OrderIDColumn.InternalName, "10248");

myKeyValue.AddElement(Order_DetailsTable.Instance.ProductIDColumn.InternalName, "72");

 

Order_DetailsRecord myRecord= Order_DetailsTable.GetRecord(myKeyValue, false);

Visual Basic .NET

Dim myKeyValue As New BaseClasses.Data.KeyValue

myKeyValue.AddElement(Order_DetailsTable.Instance.OrderIDColumn.InternalName, "10248")

myKeyValue.AddElement(Order_DetailsTable.Instance.ProductIDColumn.InternalName, "72")

Dim myRecord As Order_DetailsRecord = Order_DetailsTable.GetRecord(myKeyValue, False)