원본 : http://www.sarangnamu.net/basic/basic_v ··· ory%3D33
stdafx.h 내부
------------ 아래코드 삽입 -----------------------------
#pragma warning(push) //ado 버그로 인한 컴파일시 경고 뜨는것 방지.
#pragma warning(disable:4146)
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
rename("EOF", "EndOfFile") no_namespace
#pragma warning(pop)
-----------------------------------------------------
app 헤더
------------------
inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
------------------
app 함수쪽
------------------
InitInstance 에 다음과 같이 삽입
if(FAILED(::CoInitialize(NULL))) {
AfxMessageBox("::CoInitialize 실패했습니다.\n프로그램을 정상적으로 사용할 수 없어서 종료합니다.", MB_ICONSTOP);
}
-----------------
======================================================================
void CAdo_cnDlg::OnButton1()
{
_ConnectionPtr pConnection = NULL;
_RecordsetPtr pRecordset=NULL;
TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
_bstr_t strCnn("Provider=SQLOLEDB.1;Password=xxxxxxx;Persist Security Info=True;User ID=xxxxxxxx;Initial Catalog=xxxx;Data Source=200.100.00.000");
TESTHR(pConnection->Open(strCnn, L"", L"", -1));
CString sQuery;
sQuery.Format("select * from em_tran_test");
pRecordset = pConnection->Execute((_bstr_t)sQuery, NULL, adOptionUnspecified);
_variant_t vData;
while (!pRecordset->GetEndOfFile()) {
vData = pRecordset->GetCollect(L"tran_date"); //tran_date 는 필드명임
// 작업들
pRecordset->MoveNext();
}
//도움말에 의거하면 다음 세 스텝은 자동으로 호출되기 때문에 없어도 된다고 함..
pRecordset->Close();
pConnection->Close();
pConnection.Release();
}
=====================================================================
[삽입]
CString sQuery;
sQuery.Format("Insert Into 테이블명 (필드1, 필드2, 필드3, 필드4) values('%s', %d, %lf, 1)", sVal, nVal, dVal);
pRecordset = pConnection->Execute((_bstr_t)sQuery, NULL, adOptionUnspecified); //쿼리문 실행
[삭제]
CString sQuery;
sQuery.Format("delete from 테이블명 where 조건");
pRecordset = pConnection->Execute((_bstr_t)sQuery, NULL, adOptionUnspecified); //쿼리문 실행
[수정]
CString sQuery;
sQuery.Format('Update 테이블명 set 필드1=%lf, 필드2='%s', 필드3=%d where 조건", dVal1, sVal, dVal2);
pRecordset = pConnection->Execute((_bstr_t)sQuery, NULL, adOptionUnspecified); //쿼리문 실행
- Using ADO.NET with SQL Server (0)2007/04/29
- [Class] ADODB Connect (0)2007/04/03
- ADODB Manual (0)2007/04/03
- DB 작업을 보다 쉽게 해보자...(OTL 소개) (2)2007/01/09
- ADO for Performance (0)2007/01/09

수안이의 컴퓨터 연구실



Leave your greetings.