由于工程比较大,抽出部分代码。
1、下面是查询数据库:
m_strQuerySql = GetQuerySql();//"select * from
if (m_strQuerySql == "")
{
return;
}
_RecordsetPtr pRes = NULL;
pRes = DBManager::getInstance().QueryOracleData(m_strQuerySql.c_str());
m_pRecordSet = pRes; //类变量赋值
long RecodCount = pRes->GetRecordCount(); //总记录数
long FieldCount = pRes->GetFields()->Count; //字段数
m_nMaxCount = RecodCount;
m_nMaxPage = RecodCount / PAGERECORD + 1; //分页显示,总页数
2、CListCtrl分页显示:
可以根据自己的字段数修改代码。
#define PAGERECORD 50
每页显示50条
传入page以0开始。
void CDlgOracleQuery::SetPageData( int nPage )
{
if(nPage>=0 && nPage < m_nMaxPage)
{
m_historyData.DeleteAllItems();
int nIndex = (nPage) * PAGERECORD;
CString strTemp;
long FieldCount = m_pRecordSet->GetFields()->Count;
_variant_t fieldValue = NULL;
DWORD dwCount = 0;
if (nPage == 0)
{
m_pRecordSet->MoveFirst();
}
else
{
m_pRecordSet->MoveFirst();
m_pRecordSet->Move(nIndex);
}
while (!m_pRecordSet->EndOfFile)
{
for (int j = 0;j < FieldCount;j++)
{
fieldValue = m_pRecordSet->GetCollect(_variant_t((long)j));
if(fieldValue.vt==VT_NULL || fieldValue.vt==VT_EMPTY)
{
strTemp = "0";
}
else
{
strTemp = (LPCSTR)_bstr_t(fieldValue);
strTemp.TrimRight();
}
switch (j)
{
case 0:
{
m_historyData.InsertItem( dwCount, strTemp);
break;
}
case 1:
{
m_historyData.SetItemText(dwCount, j, strTemp);
break;
}
case 2:
{
m_historyData.SetItemText(dwCount, j, strTemp);
break;
}
case 3:
{
m_historyData.SetItemText(dwCount, j, strTemp);
break;
}
default:
break;
}
}
m_pRecordSet->MoveNext();
dwCount++;
if (dwCount == PAGERECORD)
{
break;
}
}
}
}