ado接口使用说明文档.docx
- 文档编号:9941054
- 上传时间:2023-05-22
- 格式:DOCX
- 页数:40
- 大小:25.66KB
ado接口使用说明文档.docx
《ado接口使用说明文档.docx》由会员分享,可在线阅读,更多相关《ado接口使用说明文档.docx(40页珍藏版)》请在冰点文库上搜索。
ado接口使用说明文档
Ado接口文档说明使用方法
1.CADODatabase:
:
Open(BOOLOpen(LPCTSTRlpstrConnection=_T(""));)
说明:
打开数据库,和数据原的连接过程,
例子1:
CADODatabasepAdoDb;
CStringstrConnection=_T("");
strConnection=_T("Provider=MSDASQL;PersistSecurityInfo=False;"
"Trusted_Connection=Yes;"
"DataSource=AccessSqlServer;catalog=sampledb");
pAdoDb.SetConnectionString(strConnection);
if(pAdoDb.Open())
DoSomething();
连接ServesSQL数据库的例子
例子2:
CADODatabasepAdoDb;
CStringstrConnection=_T("");
strConnection=_T("Provider=Microsoft.Jet.OLEDB.4.0;"
"DataSource=C:
\\VCProjects\\ADO\\Test\\dbTest.mdb");
pAdoDb.SetConnectionString(strConnection);
if(pAdoDb.Open())
DoSomething();
连接ACCESSDATABASE数据库的例子
2.CADODatabase:
:
Execute(BOOLExecute(LPCTSTRlpstrExec))
说明:
嵌入SQL语句,可以执行完整的SQL来操作数据库
例子:
CADODatabasepAdoDb;
CStringstrConnection=_T("");
strConnection=_T("Provider=MSDASQL;"
"PersistSecurityInfo=False;"
"Trusted_Connection=Yes"
"DataSource=AccessSqlServer;catalog=sampledb");
if(pAdoDb.Open(strConnection))
pAdoDb.Execute("DeleteFromtblClientsWhereCheker=3");
3.CADODatabase:
:
GetActiveConnection
说明:
得到当前的数据库连接
4.CADODatabase:
:
GetRecordCount((_RecordsetPtrm_pRs)
说明,得到当前查询到的记录数目
//SamplewithConnectionstringforSQLServer
CADODatabasepAdoDb;
CStringstrConnection=_T("");
strConnection=_T("Provider=MSDASQL;PersistSecurityInfo=False;"
"Trusted_Connection=Yes;"
"DataSource=AccessSqlServer;catalog=sampledb");
pAdoDb.SetConnectionString(strConnection);
if(pAdoDb.Open())
DoSomething();
.
.
.
//SamplewithConnectionStringforAccessdatabase
CADODatabasepAdoDb;
CStringstrConnection=_T("");
strConnection=_T("Provider=Microsoft.Jet.OLEDB.4.0;"
"DataSource=C:
\\VCProjects\\ADO\\Test\\dbTest.mdb");
pAdoDb.SetConnectionString(strConnection);
if(pAdoDb.Open())
DoSomething();
.
.
.
CADODatabase:
:
Execute
TheExecutefunctionexecutesasqlstatementintheopendatabase.
BOOLExecute(LPCTSTRlpstrExec)
Parameters
LPCTSTRlpstrExecAstringpointercontaininigthesqlstatementtoexecute.
CADODatabasepAdoDb;
CStringstrConnection=_T("");
strConnection=_T("Provider=MSDASQL;"
"PersistSecurityInfo=False;"
"Trusted_Connection=Yes"
"DataSource=AccessSqlServer;catalog=sampledb");
if(pAdoDb.Open(strConnection))
pAdoDb.Execute("DeleteFromtblClientsWhereCheker=3");
ReturnValue
ThefunctionreturnsTRUEifwassuccesfully.
CADODatabase:
:
GetRecordsAffected
TheGetRecordsAffctedfunctionreturnsthenumberofrecordsaffectedtothelastsqlstatementexecuted.
intGetRecordsAffected();
CADODatabase:
:
GetActiveConnection
TheGetActiveConnectionreturnstheactiveconnection.
_ConnectionPtrGetActiveConnection();
CADODatabase:
:
GetRecordCount
GetRecordCountreturnsthenumberofrecordsaffectedinaquery.
DWORDGetRecordCount(_RecordsetPtrm_pRs);
Parameters
_RecorsetPtrm_PrsTherecordset.
CADODatabase:
:
BeginTransaction
Callthisfunctiontoinitiateatransaction.AfteryoucallBeginTransaction,updatesyoumaketoyourdatatakeeffectwhenyoucommitthetransaction.
longBeginTransaction();
CADODatabase:
:
CommitTransaction
CallCommitTransactionfunctiontocommitatransactionforexamplesaveagroupofeditsandupdatestooneormoredatabases.
longCommitTransaction();
CADODatabase:
:
RollbackTransaction
CallRollbackTransactionfunctiontoendthecurrenttransactionandrestorealldatabasestotheirconditionbeforethetransactionwasbegun.
longRollbackTransaction();
CADODatabase:
:
IsOpen
TheIsOpenfuntionreturnsthestatusoftheconnectionwiththedatabase.
BOOLIsOpen();
ReturnValue
ThefunctionreturnsTRUEiftheconnectiontodatabaseisopen.
CADODatabase:
:
Close
TheClosefunctionclosetheconnectiontothedatabase.
voidClose();
CADODatabase:
:
SetConnectionString
WiththeSetConnectionStringYoucaninserttheconnectionstring.
voidSetConnectionString(LPCTSTRlpstrConnection);
Parameters
LPCTSTRlpstrConnectionAconnectionstringusedforopeningthedatabase.
seeCADODatabase:
:
Open()
CADODatabase:
:
GetConnectionString
TheGetConnectionStringfunctionreturnstheconnectionstringusedformakeaconnectionwithadatabase.
CStringGetConnectionString();
CADODatabase:
:
GetLastError
TheGetLastErrorfunctionreturnsthelasterrorcode.
DWORDGetLastError();
CADODatabase:
:
GetLastErrorString
TheGetLastErrorStringfunctionreturnsthelasterrorstring.
CStringGetLastErrorString();
TheCADORecordsetClass
TheCADORecordsetclasshasasetoffunctionsthatcorrespondstothe_RecordsetPtr.
CADORecordset:
:
CADORecordset
CreatesaCADORecordsetobject.
CADODatabase();
CADORecordset(CADODatabase*pAdoDatabase);
Parameters
CADODatabase*pAdoDatabaseACADODatabaseobjectpointer.
CADORecordset:
:
Open
TheOpenfunctionopensarecordset
BOOLOpen(_ConnectionPtrmpdb,LPCTSTRlpstrExec=_T(""),
intnOption=CADORecordset:
:
openUnknown);
BOOLOpen(LPCTSTRlpstrExec=_T(""),
intnOption=CADORecordset:
:
openUnknown);
Parameters
_ConnectionPtrmpdbAconnectionpointer.
LPCTSTRlpstrExecAstringpointercontaininiganSQLselectstatement.
intnOptionAnintegerthatdefinestheaccessmode.Thevaluesareasfollows:
CADORecordset:
:
openUnknown
CADORecordset:
:
openQuery
CADORecordset:
:
openTable
CADORecordset:
:
openStoredProc
ReturnValue
ReturnsTRUEifwassuccessfully.
Seesample
CADORecordset:
:
Execute
TheExecutefunctionopensarecordset
BOOLExecute(CADOCommand*pCommand);
Parameters
CADOCommand*pCommandACADOCommandpointer.
ReturnValue
ReturnsTRUEifwassuccessfully.
Seesample
CADORecordset:
:
GetQuery;
GetQueryreturnsthestringcontainingtheSQLSelectstatement.
CStringGetQuery();
CADORecordset:
:
SetQuery
voidSetQuery(LPCSTRstrQuery);
Parameters
LPCTSTRstrQueryAstringpointercontaininiganSQLSelectstatement.
CADORecordset:
:
RecordBinding
BOOLRecordBinding(CADORecordBindingpAdoRecordBinding);
Parameters
CADORecordBindingpAdoRecordBinding
CADORecordset:
:
GetRecordCount
GetRecordCountreturnsthenumberofrecordsaccessedintherecordset
DWORDGetRecordCount();
Seesample
CADORecordset:
:
IsOpen
IsOpendeterminesiftherecordsetisopen.
BOOLIsOpen();
ReturnValue
ThismemberfunctionreturnsTRUEiftherecordsethasnotbeenclosed.
CADORecordset:
:
Close
TheClosefunctionclosestherecordset.
voidClose();
Seesample
CADORecordset:
:
GetFieldCount
TheGetFieldCountfunctionreturnsthenumberoffieldsintherecordset.
longGetFieldCount();
CADORecordset:
:
GetFieldValue
TheGetFieldValuefunctionreturnsavaluethatcontainsthevalueofafield.
BOOLGetFieldValue(LPCTSTRlpFieldName,intnValue);
BOOLGetFieldValue(intnIndex,intnValue);
BOOLGetFieldValue(LPCTSTRlpFieldName,longlValue);
BOOLGetFieldValue(intnIndex,longlValue);
BOOLGetFieldValue(LPCTSTRlpFieldName,unsignedlongulValue);
BOOLGetFieldValue(intnIndex,unsignedlongulValue);
BOOLGetFieldValue(LPCTSTRlpFieldName,doubledbValue);
BOOLGetFieldValue(intnIndex,doubledbValue);
BOOLGetFieldValue(LPCTSTRlpFieldName,CStringstrValue,
CStringstrDateFormat=_T(""));
BOOLGetFieldValue(intnIndex,CStringstrValue,
CStringstrDateFormat=_T(""));
BOOLGetFieldValue(LPCTSTRlpFieldName,COleDateTimetime);
BOOLGetFieldValue(intnIndex,COleDateTimetime);
BOOLGetFieldValue(LPCTSTRlpFieldName,boolbValue);
BOOLGetFieldValue(intnIndex,boolbValue);
BOOLGetFieldValue(LPCTSTRlpFieldName,COleCurrencycyValue);
BOOLGetFieldValue(intnIndex,COleCurrencycyValue);
Parameters
LPCTSTRlpFieldNameApointertoastringthatcontainsthenameofafield.
intnIndexAzero-basedindexofthefieldintherecordset’sFieldscollection,forlookupbyindex.
doubledbValueAreferencetoaobjectthatwillstorethevalueofafield.
longlValueAreferencetoaobjectthatwillstorethevalueofafield.
unsignedlongulValueAreferencetoaobjectthatwillstorethevalueofafield.
intnValueAreferencetoaobjectthatwillstorethevalueofafield.
CStringstrValueAreferencetoaobjectthatwillstorethevalueofafield.
CStringstrDateFormatAformattingtimestringsimilartothestrftimeformattingstring.Themorecommonare:
∙%a Abbreviatedweekdayname
∙%A Fullweekdayname
∙%b Abbreviatedmonthname
∙%B Fullmonthname
∙%c Dateandtimerepresentationappropriateforlocale
∙%d Dayofmonthasdecimalnumber(01-31)
∙%H Hourin24-hourformat(00-23)
∙%I Hourin12-hourformat(01-12)
∙%j Dayofyearasdecimalnumber(001-366)
∙%m Monthasdecimalnumber(01-12)
∙%M Minuteasdecimalnumber(00-59)
∙%p Currentlocale’sA.M./P.M.indicatorfor12-hourclock
∙%S Secondasdecimalnumber(00-59)
∙%U Weekofyearasdecimalnumber,withSundayasfirstdayofweek(00-53)
∙%w Weekdayasdecimalnumber(0-6;Sundayis0)
∙%W Weekofyearasdecimalnumber,withMondayasfirstdayofweek(00-53)
∙%x Daterepresentationforcurrentlocale
∙%X Timerepresentationforcurrentlocale
∙%y Yearwithoutcentury,asdecimalnumber(00-99)
∙%Y Yearwithcentury,asdecimalnumber
COleDateTimetimeAreferencetoaobjectthatwillstorethevalueofafield.
boolbValueAreferencetoaobjectthatwillstorethevalueofafield.
COleCurrencycyValueAreferencetoaobjectthatwillstorethevalueofafield.
Seesample
CADORecordset:
:
IsFieldNull
TheIsFieldNullfunctiondeterminesifthefielddataisnull.
BOOLIsFieldNull(LPCTSTRlpFieldName);
BOOLIsFieldNull(intnIndex);
Parameters
LPCTSTRlpFieldNameApointertoastringthatcontainsthenameofafield.
intnIndexAzero-basedindexofthefieldintherecordset’sFieldscollection,forlookupbyindex.
ReturnValue
Thisfunctionre
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ado 接口 使用说明 文档