操作ACCESS的类CADOConn (七)

2014-11-24 03:07:08 · 作者: · 浏览: 14
switch(iType)
{
case ado_Field_Str:
case ado_Field_Text:
strValue = GetItemString(i);
break;
case ado_Field_Long:
strValue.Format(_T("%d"), GetItemLong(i));
break;
case ado_Field_Int:
strValue.Format(_T("%d"), GetItemInt(i));
break;
// case ado_Field_Float:
// strValue=GetValueFloatStr(i,0,2);
// break;
// case ado_Field_Double:
// strValue=GetValueDoubleStr(i,0,2);
// break;
// case ado_Field_Byte:
// strValue=GetValueByteStr(i,0);
// break;
case ado_Field_Date:
strValue = GetItemString(i);
break;
default:
strValue = "";
break;
}

if(i == 0)
listMain->InsertItem(iRow, strValue, 0);
else
listMain->SetItemText(iRow, i, strValue);
}
m_pRecordset->MoveNext();
}
//移向开头
MoveFirst();
}

return TRUE;
}

// ADOConn.h: interface for the CADOConn class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_ADOCONN_H__6FC87078_9BAB_4B1F_B205_E932FD387E09__INCLUDED_)
#define AFX_ADOCONN_H__6FC87078_9BAB_4B1F_B205_E932FD387E09__INCLUDED_

#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename ("EOF", "adoEOF")

#define ado_Field_Str 202
#define ado_Field_Text 203
#define ado_Field_Int 2
#define ado_Field_Long 3
#define ado_Field_Float 4
#define ado_Field_Double 5
#define ado_Field_Date 7
#define ado_Field_Byte 17


#ifdef _DEBUG
#define ASSERT_VALID_STRING( str ) ASSERT( !IsBadStringPtr( str, 0xfffff ) )
#else // _DEBUG
#define ASSERT_VALID_STRING( str ) ( (void)0 )
#endif // _DEBUG

class CADOConn
{
public:
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
_bstr_t m_strDatabaseName;
int m_iDatabaseType;

CADOConn();
CADOConn(CString m_strDatabaseName);
virtual ~CADOConn();
CString GetAppPath();
void InitCADOConn();
void ExitConnect();
_RecordsetPtr& GetRecordSet(CString strSQL);
BOOL Open(CString strSQL);
BOOL ExecuteSQL(CString strSQL);
BOOL MoveFirst();
BOOL MoveNext();
CString GetItemString(int index);
int GetItemInt(int index);
long GetItemLong(int index);
BOOL adoEOF();
CString GetFieldName(int index);
int GetFieldsCount();
long GetRecordCount();
BOOL InitList(CListCtrl *listMain);
BOOL FillList(CListCtrl *listMain);
};

#endif // !defined(AFX_ADOCONN_H__6FC87078_9BAB_4B1F_B205_E932FD387E09__INCLUDED_)

// ADOConn.cpp: implementation of the CADOConn class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ADOConn.h"


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////