
CDatabase对象表示到数据源的连接,通过它可以操作数据源。
- 中文名称 数据源的连接
- 外文名称 CDatabase
- 功能 数据源操作
- 数据源 MicrosoftSQL Server
- 辅助 OpenEx成员函数
CDa宜天营持语呢针破低历tabase详解
数据源是位于一些数据库管理系统(DBMS)的数据的指定实例,包括MicrosoftSQLServer,MicrosoftAccess,BorlanddBASE和来自xBASE。在应用中可以同时使一个或多个CDatabase对象活动。
注意:
去块高如果在处理数据访问对象(DAO)类而不是开放数据库连接(ODBC)类,可使用类CDaoDatabase。有关的更多信息,请参阅联机文档"Visual C内身得画再木下家为老改++程序员指南"中的"数据库主题(通用)"与"DAO和MFC"。
为使用CDatabase,构造一个CDatabase对象并调用它的OpenEx成员函数。这打开了一个连接。在接着构造CRecordset对象以操纵连接的数据源时,向CDatabase对象传递记录集构造程序指针。完成使用连接时调用Close成员函数并销毁减越治穿CDatabase对象。Close关闭以前没有关闭判阳路赵常的任何记录集。
D360百科ata Members
m_江况赶体贵hdbc | Open Database Connectivity (ODBC) connection hand针由小比编跟的河座移置le to a dat们巴从失a source. T握道它ype HDBC. |
Construction
CDatabase | Constructs a CDatabase object. You mus权湖t initialize the object by calling 育居画车OpenEx or Ope假n. |
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 connec克关溶销刑信才及洲节t string used to connect the CDatabase ob刘距被文气ject to a dat制主a source. |
度责端江象IsOpen | Returns nonzero if the CDatabase object is cu团确严轮武振苦rrently 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. |
Rollback | Reverses changes made during the current transaction. The data source returns to its previous state, as defined at the BeginTrans call, unaltered. |
Cancel | 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. |
评论留言