-
CDatabase
鎖定
CDatabase對象表示到數據源的連接,通過它可以操作數據源。
- 中文名
- 數據源的連接
- 外文名
- CDatabase
- 功 能
- 數據源操作
- 數據源
- MicrosoftSQL Server
- 輔 助
- OpenEx成員函數
- 所需頭文件
- #include
- 類 型
- 計算機術語
CDatabase詳解
數據源是位於一些數據庫管理系統(DBMS)的數據的指定實例,包括MicrosoftSQLServer,MicrosoftAccess,BorlanddBASE和xBASE。在應用中可以同時使一個或多個CDatabase對象活動。
注意:
如果在處理數據訪問對象(DAO)類而不是開放數據庫連接(ODBC)類,可使用類CDaoDatabase。有關的更多信息,請參閲聯機文檔“Visual C++程序員指南”中的“數據庫主題(通用)”與“DAO和MFC”。
為使用CDatabase,構造一個CDatabase對象並調用它的OpenEx成員函數。這打開了一個連接。在接着構造CRecordset對象以操縱連接的數據源時,向CDatabase對象傳遞記錄集構造程序指針。完成使用連接時調用Close成員函數並銷燬CDatabase對象。Close關閉以前沒有關閉的任何記錄集。
Data Members
m_hdbc | Open Database Connectivity (ODBC) connection handle to a data source. Type HDBC. |
Construction
CDatabase | Constructs a CDatabase object. You must initialize the object by calling OpenEx or Open. |
Open | Establishes a connection to a data source (through an ODBC driver). |
OpenEx | Establishes a connection to a data source (through an ODBC driver). |
Close | Closes the data source connection. |
- Database Attributes
GetConnect | Returns the ODBC connect string used to connect the CDatabase object to a data source. |
IsOpen | Returns nonzero if the CDatabase object is currently connected to a data source. |
GetDatabaseName | Returns the name of the database currently in use. |
CanUpdate | Returns nonzero if the CDatabase object is updatable (not read-only). |
CanTransact | Returns nonzero if the data source supports transactions. |
SetLoginTimeout | Sets the number of seconds after which a data source connection attempt will time out. |
SetQueryTimeout | Sets the number of seconds after which database query operations will time out. Affects all subsequent recordset Open, AddNew, Edit, and Delete calls. |
GetBookmarkPersistence | Identifies the operations through which bookmarks persist on recordset objects. |
GetCursorCommitBehavior | Identifies the effect of committing a transaction on an open recordset object. |
GetCursorRollbackBehavior | Identifies the effect of rolling back a transaction on an open recordset object. |
- Database Operations
BeginTrans | Starts a “transaction” — a series of reversible calls to the AddNew, Edit, Delete, and Update member functions of class CRecordset — on the connected data source. The data source must support transactions for BeginTrans to have any effect. |
BindParameters | Allows you to bind parameters before calling CDatabase::ExecuteSQL. |
CommitTrans | Completes a transaction begun by BeginTrans. Commands in the transaction that alter the data source are carried out. |
Reverses changes made during the current transaction. The data source returns to its previous state, as defined at the BeginTrans call, unaltered. | |
Cancels an asynchronous operation or a process from a second thread. | |
ExecuteSQL | Executes an SQL statement. No data records are returned. |
所需頭文件:#include <afxdb.h>
- Database Overridables
OnSetOptions | Called by the framework to set standard connection options. The default implementation sets the query timeout value. You can establish these options ahead of time by calling SetQueryTimeout. |
- 詞條統計
-
- 瀏覽次數:次
- 編輯次數:13次歷史版本
- 最近更新: 以酒E取暖