//假定m_pSet是你的CRecordset派生类.
LONG getsum(CRecordset *m_pSet){
CRecordset aTempSet;
LONG l=0;
if (aTempSet.Open(CRecordset::forwardOnly,"select sum([fieldname]) from "+m_pSet->GetDefaultSQL())){
CDBVariant dbv;
aTempSet.GetFieldValue((short)0,dbv);
if (dbv.m_dwType==DBVT_LONG) l=dbv.m_lVal;
else if (dbv.m_dwType==DBVT_SHORT) l=dbv.m_iVal;
else if (dbv.m_dwType==DBVT_STRING) l=_ttoi((LPCTSTR)(*dbv.m_sVal));//针对oracle的返回可能是string处理...
else ASSERT(FALSE);
}
aTempSet.Close();
return l;
}
LONG getsum(CRecordset *m_pSet){
CRecordset aTempSet;
LONG l=0;
if (aTempSet.Open(CRecordset::forwardOnly,"select sum([fieldname]) from "+m_pSet->GetDefaultSQL())){
CDBVariant dbv;
aTempSet.GetFieldValue((short)0,dbv);
if (dbv.m_dwType==DBVT_LONG) l=dbv.m_lVal;
else if (dbv.m_dwType==DBVT_SHORT) l=dbv.m_iVal;
else if (dbv.m_dwType==DBVT_STRING) l=_ttoi((LPCTSTR)(*dbv.m_sVal));//针对oracle的返回可能是string处理...
else ASSERT(FALSE);
}
aTempSet.Close();
return l;
}
LONG getsum(CRecordset *m_pSet/*要统计的记录集*/,LPCTSTR pfldnametosum/*要统计的字段*/){
CRecordset aTempSet(m_pSet->m_pDatabase);
LONG l=0;
CString sqlstr;
sqlstr.Format("select sum([%s]) from %s",
pfldnametosum,
m_pSet->GetDefaultSQL());if (aTempSet.Open(CRecordset::forwardOnly,sqlstr){
CDBVariant dbv;
aTempSet.GetFieldValue((short)0,dbv);
if (dbv.m_dwType==DBVT_LONG) l=dbv.m_lVal;
else if (dbv.m_dwType==DBVT_SHORT) l=dbv.m_iVal;
else if (dbv.m_dwType==DBVT_STRING) l=_ttoi((LPCTSTR)(*dbv.m_sVal));//针对oracle的返回可能是string处理...
else ASSERT(FALSE);
aTempSet.Close();
}
return l;
}