您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > 数据库 > jsj_Visual C++数据库编
C++VisualC++ODBCODBC(OpenDatabaseConnectivity,)(WOSA,WindowsOpenServicesArchitecture),,API)APISQL(..ODBCSQL,SQLODBC.ODBCDBMS,DBMS,DBMSODBC.,FoxPro,AccessOracle,ODBCAPI.,ODBC.ODBC:(Application).ODBC(Administrator).Windows95(ControlPanel)32ODBC,ODBC.(DriverManager).ODBC32.DLL,.ODBC,ODBC.ODBCAPI.ODBC.DLL,ODBC..,.::,ODBC,,ODBC,ODBC.,ODBC,ODBC.ODBC,ODBCAPI,.ODBCAPI,,.ODBCODBC.VisualC++5.0SQLServer,Access,Paradox,dBase,FoxPro,Excel,OracleMicrosoftText.,VC5.0SQLServer,Access,FoxProdBase.,VC5.0.ADO(ADO),VisualC++ADO,ADO(ODBC).:VisualC++:1ADOCOM(ADO)COM.ADOCOM,,C++,VisualBasic,DelphiCOMADO.ADOOLEDB,,,,,COM,ODBC.2ADODAORDO,ADO,Connection,Command,Recordset,.ConnectionOLEDB,,;,.Command,SQL,.Recordset,,,,.ADO,.3ADO(1),ADOODBC.(2)ADOODBC,ADO.(3)ADO,,,.FMCODBC.ADO,ADOFMCRFX(,ODBCCstring).(4)ADOConnectionRecordset.(5)ADO(UpdateBatch),,.C++4ADOVisualC++MicrsoftStudio6ADO2,VisualC++ADOSQLSERVER.ADO,(VisualBasicScroptJavaScript)ADO.VisualC++ADOConnectionRecordset:(1)importADO2:#importC:\ADO\msado15.dllno_namespacerename(EOF,EndOfFile)(2)CADORecordBinding,,icrsint.h.:classCIntlive:publicCADORecordBinding{public:DBTIMESTAMPm_datetime;//ADO()longm_key;longm_value;longm_quality;WORDm_stsdatetime;//ADOWORDm_stskey;WORDm_stsvalue;WORDm_stsquality;BEGIN_ADO_BINDING(CIntlive)//ADOADO_VARIABLE_LENGTH_ENTRY2(1,adDBTimeStamp,m_datetime,sizeof(m_datetime),m_stsdatetime,true)ADO_NUMERIC_ENTRY(2,adInteger,m_key,10,0,m_stskey,true)ADO_NUMERIC_ENTRY(3,adInteger,m_value,10,0,m_stsvalue,true)ADO_NUMERIC_ENTRY(4,adInteger,m_quality,10,0,m_stsquality,true)END_ADO_BINDING()};(3)CoInitializeCOM::CoInitialize(NULL);(4)ADOConnectionRecordset.(msado15.dll):_ConnectionPtrpConnection1=NULL;_RecordsetPtrrstADO1=NULL;(5)CADORecordBindingBind.:CIntlivem_intdata;IADORecordBinding*rstADOBind1=NULL;(6)ConnectionRecordset.:pConnection1.CreateInstance(_uuidof(Connection));rstADO1.CreateInstance(__uuidof(Recordset));(7)Recordset,openMSDNADOBasic.:PConnection1-Open(driver={SQLserver};server=servera;uid=sa;pwd=;database=pubs,,,NULL);rstADO1-Open(data,_variant_t((IDispatch*)pConnection1,true),adOpenKeyset,adLockBatchOptimistic,adCmdTable);(8)CADORecordBindingRecordsetBind.:RstADOBind1-BindToRecordset(&m_intdata);(9)Recordset.MSDNADORecordsetBasic.:rstADO1-MoveNext();//rstADO1-Update(_variant_t(quality),_variant_t(3)));//quality3rstADO1-UpdateBatch(adAffectAll));//Recordset(10)RecordsetBind.:RstADO1-Close();RstADOBind2-Release();(11)pConnection1-Close();(12)CoUnitializeCOM::CoUninitialize();5ODBC,ADO.ADO,ODBC,ADO.ADO,.ADO,ADOODBC,ADO.ODBCMicrosoftDeveloperStudio32ODBC.:SQLServer,Access,Paradox,dBase,FoxPro,Excel,OracleMicrosoftText.,ODBCDBMS.DBMS,ODBC.,,.ODBC.,MFCODBCVisualC++MFC.ODBC,CDatabase(),CRecordSet()CRecordView().CDatabase,.CRecordSet.CRecordSet:(dynasets)(snapshots).,.,,,.CRecordView,CRecordSet.,ODBCVisualC++AppWizardODBC,:FileNew,Projects,,MFCAppWizard(exe),AppWizard.AppWizard,,Databaseviewwithfilesupport;,Databaseviewwithoutfilesupport.,DatabaseSource,DataOptions.DatabaseOptionsODBC,,:Super_ES,OKSelectDatabaseTables,;,OK.,AppWizard.:View(:CSuper_ESView),CSuper_ESSetm_pSet,AppWizard,,.,CDateBase::OpenEx()CDatabase::Open()..,1.1.CRecordSet::Open()CRecordSet::Requery().CRecordSet,CRecordSet::Open().CRecordSet::Open(),CRecordSet::Requery().CRecordSet::Open(),CDatabaseCRecordSetm_pDatabase,ODBC;m_pDatabase,CDatabase,,CRecordSet.GetDefaultConnect().SQL,CRecordSet::Open(),:Super_ESSet.Open(AFX_DATABASE_USE_DEFAULT,strSQL);,SQL,GetDefaultSQL()SQL:CStringCSuper_ESSet::GetDefaultSQL(){return_T([BsicData],[MinSize]);}GetDefaultSQL(),SELECT,:SELECT*FROMBasicData,MainSize,CRecordSetm_strFilterm_strSort.m_strFilter,SQLWHERE;m_strSort,SQLORDERBY.:Super_ESSet.m_strFilter=TYPE='';Super_ESSet.m_strSort=VOLTAGE;Super_ESSet.Requery();SQL:SELECT*FROMBasicData,MainSizeWHERETYPE=''ORDERBYVOLTAGEm_strFilter,.,.:S:CStringp1;floatp2;S:p1=_T();p2=0.0f;m_nParams=2;S:pFX-SetFieldType(CFieldExchange::param)RFX_Text(pFX,_T(P1),p1);RFX_Single(pFX,_T(P2),p2);:m_pSet-m_strFilter=TYPE=?ANDVOLTAGE=?;m_pSet-p1=;m_pSet-p2=60.0;m_pSet-Requery();?.,CRecordSetMove(),MoveNext(),MovePrev(),MoveFirst()MoveLast().2.2.AddNew(),:m_pSet-AddNew();//m_pSet-SetFieldNull(&(m_pSet-m_type),FALSE);m_pSet-m_type=;……//m_pSet-Update();//m_pSet-Requery();//3.3.Delete(),Delete()Update():m_pSet-Delete();if(!m_pSet-IsEOF())m_pSet-MoveNext();elsem_pSet-MoveLast();4.4.Edit():m_pSet-Edit();//m_pSet-m_type=;//……m_pSet-Update();//m_pSet-Requery();5.5.,Update():CRecordSet::Move(AFX_MOVE_REFRESH),.,AFX_MOVE_REFRESH.6.6.CRecordSetm_pDatabase:CDatabase*m_pDatabase;.CRecordSetOpen(),CDatabasem_pDatabase,CDatabase.:CDatabasem_db;CRecordSetm_set1,m_set2;m_db.Open(_T(Super_ES));//ODBCm_set1.m_pDatabase=&m_db;//m_set1m_dbm_set2.m_pDatabse=&m_db;//m_set2m_db7.SQLCRecordSet,CRecordSet::Open()SQL,,,,,CDatabaseSQL.CDatabase::ExecuteSQL()SQL:BOOLCDB::ExecuteSQLAndReportFailure(constCString&strSQL){TRY{m_pdb-ExecuteSQL(strSQL);//SQL}CATCH(CDBException,e){CStringstrMsg;strMsg.LoadString(IDS_EXECUTE_SQL_FAI
本文标题:jsj_Visual C++数据库编
链接地址:https://www.777doc.com/doc-6226102 .html