home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bde / snipit.pak / TBLOPEN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  3.1 KB  |  80 lines

  1. // BDE - (C) Copyright 1995 by Borland International
  2.  
  3. // tblopen.c
  4. #include "snipit.h"
  5.  
  6. static const char szTblName[] = "cust";
  7. static const char szTblType[] = szDBASE;
  8.  
  9. //=====================================================================
  10. //  Function:
  11. //          TableOpen();
  12. //
  13. //  Description:
  14. //          This example shows how to open and close a table.
  15. //=====================================================================
  16. void
  17. TableOpen (void)
  18. {
  19.     DBIResult  rslt;       // Return value from IDAPI functions
  20.     hDBIDb     hDb;        // Handle to the database
  21.     hDBICur    hCur;       // Handle to the table
  22.  
  23.     Screen("*** Opening a Table ***\r\n");
  24.  
  25.     BREAK_IN_DEBUGGER();
  26.  
  27.     Screen("    Initializing IDAPI...\r\n");
  28.     if (InitAndConnect(&hDb) != DBIERR_NONE)
  29.     {
  30.         Screen("\r\n*** End of Example ***");
  31.         return;
  32.     }
  33.  
  34.     Screen("    Setting the database directory...");
  35.     
  36.     rslt = DbiSetDirectory(hDb, (pCHAR) szTblDirectory);
  37.     ChkRslt(rslt, "SetDirectory");
  38.  
  39.     Screen("    Opening the %s table...", szTblName);
  40.     rslt = DbiOpenTable(hDb,                // Handle to the database of the
  41.                                             //   table Paradox and dBASE use
  42.                                             //   the standard database
  43.                         (pCHAR) szTblName,  // Name of the table
  44.                         (pCHAR) szTblType,  // Type of the table - not needed
  45.                                             //   if the table name contains
  46.                                             //   an extension
  47.                         NULL,               // Index name
  48.                         NULL,               // Index tag name
  49.                         NULL,               // Index ID
  50.                         dbiREADWRITE,       // Open the table for both reading
  51.                                             //   and writing
  52.                         dbiOPENSHARED,      // Open the table in shared mode -
  53.                                             //   other applications can have
  54.                                             //   concurrent access
  55.                         xltFIELD,           // Field values are translated from
  56.                                             //   internal Paradox types to
  57.                                             //   types usable in the
  58.                                             //   application
  59.                         FALSE,              // Unidirectional - Yes, No
  60.                         NULL,               // Optional parameters
  61.                         &hCur);             // Cursor handle to the table
  62.     if (ChkRslt(rslt, "OpenTable") != DBIERR_NONE)
  63.     {
  64.         CloseDbAndExit(&hDb);
  65.         Screen("\r\n*** End of Example ***");
  66.         return;
  67.     }
  68.  
  69.     Screen("\r\n    The %s table was opened successfully!\r\n", szTblName);
  70.  
  71.     Screen("    Close the %s table...", szTblName);
  72.     rslt = DbiCloseCursor(&hCur);
  73.     ChkRslt(rslt, "CloseCursor");
  74.  
  75.     Screen("    Close the database and exit IDAPI...");
  76.     CloseDbAndExit(&hDb);
  77.  
  78.     Screen("\r\n*** End of Example ***");
  79. }
  80.