Export (0) Print
Expand All
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Searching for a Record

Windows CE 3.0

Before you can read and write a record in a database, you must find the record. Use CeSeekDatabase to move the database seek pointer to the record that you want to read from or write to. CeSeekDatabase always uses the current sort order as it is specified in the call to CeOpenDatabaseEx. CeSeekDatabase can search through a database for a relative or exact property value, a relative or exact location, or a record object identifier (CEOID). However, Windows CE can perform a seek operation only on a property value for which a sort order exists. When CeSeekDatabase finds a record, Windows CE positions the seek pointer at that record. Any subsequent read operation takes place at the location of the seek pointer. If you set the CEDB_AUTOINCREMENT flag in your call to CeOpenDatabaseEx, each read operation automatically increments the seek pointer from the current record to the next record.

Seek operations are affected by the sort order that is associated with the open database handle. For example, suppose that the Contacts database was opened by using a sort operation on the name property. If you specify the CEDB_SEEK_VALUEFIRSTEQUAL flag and a value of "John Smith," CeSeekDatabase searches from the beginning of the database looking only at the name property of each record. It stops when, and if, it finds a matching property.

The following code example shows how to search for a record by using CeSeekDatabase.

void UsingCeSeekDatabase (void)
  CEOID CeOid;          // Object identifier
  CEOID CeOidSeek;      // Object identifier
  DWORD dwIndex;        // Index of record to seek
  TCHAR szError[100];   // String for displaying error messages
  HANDLE hDataBase;     // Handle to a user-allocated heap

  // Assign to CeOidSeek the object identifier of the record
  // being searched for.
  // ...

  // Call CeOpenDatabaseEx to open the database.
  // hDataBase = CeOpenDatabaseEx {...}

  // Perform the seek. This type of seek operation is very efficient.
  if ((CeOid = CeSeekDatabase(
              hDataBase,        // Handle of the database
              CEDB_SEEK_CEOID,  // Finding an object with the
                                // same identifier
              CeOidSeek,        // Specifies the record to seek
              &dwIndex          // If successful, moves the database
                                // pointer to point to the record
                )) == 0)
    wsprintf (szError, TEXT("ERROR: CeSeekDatabase failed (%ld)"),
                          GetLastError ());

} // End of UsingCeSeekDatabase example code

© 2015 Microsoft