ado接口使用说明文档.docx

上传人:b****0 文档编号:9941054 上传时间:2023-05-22 格式:DOCX 页数:40 大小:25.66KB
下载 相关 举报
ado接口使用说明文档.docx_第1页
第1页 / 共40页
ado接口使用说明文档.docx_第2页
第2页 / 共40页
ado接口使用说明文档.docx_第3页
第3页 / 共40页
ado接口使用说明文档.docx_第4页
第4页 / 共40页
ado接口使用说明文档.docx_第5页
第5页 / 共40页
ado接口使用说明文档.docx_第6页
第6页 / 共40页
ado接口使用说明文档.docx_第7页
第7页 / 共40页
ado接口使用说明文档.docx_第8页
第8页 / 共40页
ado接口使用说明文档.docx_第9页
第9页 / 共40页
ado接口使用说明文档.docx_第10页
第10页 / 共40页
ado接口使用说明文档.docx_第11页
第11页 / 共40页
ado接口使用说明文档.docx_第12页
第12页 / 共40页
ado接口使用说明文档.docx_第13页
第13页 / 共40页
ado接口使用说明文档.docx_第14页
第14页 / 共40页
ado接口使用说明文档.docx_第15页
第15页 / 共40页
ado接口使用说明文档.docx_第16页
第16页 / 共40页
ado接口使用说明文档.docx_第17页
第17页 / 共40页
ado接口使用说明文档.docx_第18页
第18页 / 共40页
ado接口使用说明文档.docx_第19页
第19页 / 共40页
ado接口使用说明文档.docx_第20页
第20页 / 共40页
亲,该文档总共40页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

ado接口使用说明文档.docx

《ado接口使用说明文档.docx》由会员分享,可在线阅读,更多相关《ado接口使用说明文档.docx(40页珍藏版)》请在冰点文库上搜索。

ado接口使用说明文档.docx

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

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2