1 Access2013 OLE DBObject Linking and Embedding ODBCOpen
[1 단계] Access(2013) 실행
데이터베이스의 사용을 위한 등록 방법 • OLE DB(Object Linking and Embedding) • ODBC(Open Data. Base Connectivity) • DAO(Data Access Object)
[참고] DB 파일 설정의 다른 방법 1 CString DB 01 Path = _T("C: ₩₩Data. Base₩₩DB 01. accdb"); CString connect. DB 01; connect. DB 01. Format(_T("Provider=Microsoft. ace. oledb. 12. 0; Data Souce=%s"), DB 01 Path);
[참고] DB 파일 설정의 다른 방법 2 CString DB 01 Path = _T("C: ₩₩Data. Base₩₩DB 01. accdb"); CString connect. DB 01 = _T("Provider=Microsoft. ace. oledb. 12. 0; Data Souce="; connect. DB 01 += DB 01 Path;
[참고] DB 파일 설정의 다른 방법 3 CString DB 01 Path = _T("C: ₩₩Data. Base₩₩DB 01. accdb"); // 실행 프록드램의 위치를 설정하는 코드 TCHAR exe. Program. Path[_MAX_PATH]; Get. Module. File. Name(NULL, exe. Program. Path, _MAX_PATH); CString program. Path; program. Path = exe. Program. Path; int index; index = program. Path. Reverse. Find('₩₩'); program. Path = program. Path. Left(index+1); // DB 파일의 위치를 설정하는 코드 CString DB 01 Path; DB 01 Path. Format(_T("%s. DB 01. accdb"), program. Path); CString connect. DB 01; connect. DB 01. Format(_T("Provider=Microsoft. ace. oledb. 12. 0; Data Souce=%s"), DB 01 Path);
[함수정리] CString: : Reverse. Find() CString 개체에서 마지막으로 일치하는 위치를 취득 int Reverse. Find(TCHAR ch ) const; • ch : 검색 문자
[함수정리] CString: : Left() CString 개체에서 왼 쪽부터 지적한 문자의 수 만큼 문자열을 취득 CString Left( int n. Count ) const; throw( CMemory. Exception ); • n. Count : CString 개체에서 추출할 문자의 수
[함수정리] Co. Initialize() • Initializes the COM library on the current thread and identifies the concurrency model as single-thread apartment (STA). • New applications should call Co. Initialize. Ex instead of Co. Initialize. If you want to use the Windows Runtime, you must call Windows: : Foundation: : Initialize instead. HRESULT Co. Initialize( _In_opt_ LPVOID pv. Reserved ); • pv. Reserved : This parameter is reserved and must be NULL.
• Return value This function can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following values. Return code Description S_OK The COM library was initialized successfully on this thread. S_FALSE The COM library is already initialized on this thread. RPC_E_CHANGED_MODE A previous call to Co. Initialize. Ex specified the concurrency model for this thread as multithread apartment (MTA). This could also indicate that a change from neutral-threaded apartment to single-threaded apartment has occurred. • Remarks You need to initialize the COM library on a thread before you call any of the library functions except Co. Get. Malloc, to get a pointer to the standard allocator, and the memory allocation functions. After the concurrency model for a thread is set, it cannot be changed. A call to Co. Initialize on an apartment that was previously initialized as multithreaded will fail and return RPC_E_CHANGED_MODE. Co. Initialize. Ex provides the same functionality as Co. Initialize and also provides a parameter to explicitly specify the thread's concurrency model. Co. Initialize calls Co. Initialize. Ex and specifies the concurrency model as single-thread apartment. Applications developed today should call Co. Initialize. Ex rather than Co. Initialize. Typically, the COM library is initialized on a thread only once. Subsequent calls to Co. Initialize or Co. Initialize. Ex on the same thread will succeed, as long as they do not attempt to change the concurrency model, but will return S_FALSE. To close the COM library gracefully, each successful call to Co. Initialize or Co. Initialize. Ex, including those that return S_FALSE, must be balanced by a corresponding call to Co. Uninitialize. However, the first thread in the application that calls Co. Initialize with 0 (or Co. Initialize. Ex with COINIT_APARTMENTTHREADED) must be the last thread to call Co. Uninitialize. Otherwise, subsequent calls to Co. Initialize on the STA will fail and the application will not work. Because there is no way to control the order in which in-process servers are loaded or unloaded, do not call Co. Initialize, Co. Initialize. Ex, or Co. Uninitialize from the Dll. Main function.
[클래스정리] CData. Source • Corresponds to an OLE DB data source object, which represents a connection through a provider to a data source. • 주요 함수 Close() Closes the connection. Get. Initialization. String() Retrieves the initialization string of the data source that is currently open. Get. Properties() Gets the values of properties currently set for the connected data source. Get. Property() Gets the value of a single property currently set for the connected data source. Open() Creates a connection to a provider (data source) using either a CLSID, Prog. ID, or a CEnumerator moniker provided by the caller. Open. From. File. Name() Opens a data source from a file specified by the user-supplied file name. Open. From. Initialization. String() Opens the data source specified by an initialization string. Open. With. Prompt. File. Name() Allows the user to select a previously created data link file to open the corresponding data source. Open. With. Service. Components() Opens a data source object using the Data Link dialog box.
[함수정리] CData. Source: : Open. From. Initialization. String() • Opens a data source specified by the user-supplied initialization string. • 사용자가 제공한 초기 문자열에 의해 제공된 데이터 소스를 열음 HRESULT Open. From. Initialization. String( LPCOLESTR sz. Initialization. String, bool f. Prompt. For. Info = false ) throw( ); • sz. Initialization. String : 초기화 문자열 • f. Prompt. For. Info : true로 설정되면
• f. Prompt. For. Info : • [in] If this argument is set to true, then Open. From. Initialization. String will set the DBPROP_INIT_PROMPT property to DBPROMPT_COMPLETEREQUIRED, which specifies that the user be prompted only if more information is needed. This is useful for situations in which the initialization string specifies a database that requires a password, but the string does not contain the password. The user will be prompted for a password (or any other missing information) when trying to connect to the database. • The default value is false, which specifies that the user never be prompted (sets DBPROP_INIT_PROMPT to DBPROMPT_NOPROMPT).
[함수정리] CData. Source: : Open. From. Initialization. String() • Opens a data source specified by the user-supplied initialization string. • 사용자가 제공한 초기 문자열에 의해 제공된 데이터 소스를 열음 HRESULT Open. From. Initialization. String( LPCOLESTR sz. Initialization. String, bool f. Prompt. For. Info = false ) throw( ); • sz. Initialization. String : 초기화 문자열 • f. Prompt. For. Info : true로 설정되면
[함수정리] CData. Source: : Get. Property() • Returns the value of a specified property for the connected data source object. HRESULT Get. Property( const GUID& guid, DBPROPID propid, VARIANT* p. Variant ) const throw( ); • guid : [in] A GUID identifying the property set for which to return the property. • propid : [in] Property ID for the property to return. • p. Variant : [out] A pointer to the variant where Get. Property returns the value of the property.
[함수정리] Csession: : Close() 열린 세션을 닫음 void Close( ) throw( );
~ View. h 에서 다음과 같이 설정 CCommand<CDynamic. String. Accessor. W, CRowset> command;
[함수정리] CCommand: : Move. First() CCommand: : Move. Prev() CCommand: : Move. Next() CCommand: : Move. Last() 데이터베이스의 레코드 위치 이동
[13 단계] Setting. First() 함수 추가
[14 단계] Setting. First() 함수 코딩
[3] search. Function() 함수 코딩
- Slides: 142