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

Iron Speed Designer make it easy to retrieve records with primary, non-primary, and composite keys.
- Pooja Daga, Technical Support Engineer, Iron Speed, Inc.

April 19, 2006
Iron Speed Designer V3.2

Retrieving Records with Primary Key Using the GetRecord() Function
It is 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, .NET Framework 1.1 and 2.0:

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, .NET Framework 1.1:

Dim myRecord As OrdersRecord
myRecord = OrdersTable.Instance.GetRecord("10261", False)

Visual Basic .NET, .NET Framework 2.0

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.Instance.GetRecord(myKeyValue, false);

Visual Basic .NET, .NET Framework 1.1:

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.Instance.GetRecord(myKeyValue, False)

Visual Basic .NET, .NET Framework 2.0:

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)

About the Author
Pooja Daga
Technical Support Engineer, Iron Speed, Inc.

Pooja has experience developing Web applications using .NET technology. She started her career with PCS, a leading software services company headquartered in India and has been with Iron Speed since 2005.

Pooja holds a M.S. degree in Computer Application and a B.S. degree in Electrical engineering from Maharaja Sayajirao University in India.



  Privacy Statement