我从CRecordSet类创建了一个子类:CCommonRs
并定义了该类的一个指针m_pCommonRS,可是通过该指针显示记录时总是出问题。
执行函数如下:
BOOL CMyView::ShowInformation(CString strSQL)
{
CRect rect;
CListCtrl& ctrlList = (CListCtrl&) GetListCtrl();
ctrlList.GetWindowRect(rect); try{
// get recordset field information
BeginWaitCursor();
if(m_pCommonRS->IsOpen()) m_pCommonRS->Close();
m_pCommonRS->Open(CRecordset::dynaset, strSQL);
if(!m_pCommonRS->IsEOF()){
m_pCommonRS->MoveLast();
m_pCommonRS->MoveFirst();
}
int nFieldCount = m_pCommonRS->GetODBCFieldCount();
CODBCFieldInfo fieldinfo;
for(int n=0;n<nFieldCount;n++){
m_pCommonRS->GetODBCFieldInfo(n, fieldinfo);
int nWidth = ctrlList.GetStringWidth(fieldinfo.m_strName) + 15;
ctrlList.InsertColumn(n, fieldinfo.m_strName, LVCFMT_LEFT, nWidth);
}
// get recordset data information
CString strValue;
m_pCommonRS->MoveFirst();
int nCount = 0; while(!m_pCommonRS->IsEOF()){
ctrlList.InsertItem(nCount, strValue);
for(int j=0;j<nFieldCount;j++){
m_pCommonRS->GetFieldValue(j, strValue);
ctrlList.SetItemText(nCount, j, strValue);
}
m_pCommonRS->MoveNext();
nCount ++;
}
EndWaitCursor();
} catch(CDBException *e){
e->ReportError();
EndWaitCursor();
return FALSE;
} return TRUE;}上面try语句中的第三行m_pCommonRS->Open(CRecordset::dynaset, strSQL);有什么问题吗?程序到那里就不行了。
并定义了该类的一个指针m_pCommonRS,可是通过该指针显示记录时总是出问题。
执行函数如下:
BOOL CMyView::ShowInformation(CString strSQL)
{
CRect rect;
CListCtrl& ctrlList = (CListCtrl&) GetListCtrl();
ctrlList.GetWindowRect(rect); try{
// get recordset field information
BeginWaitCursor();
if(m_pCommonRS->IsOpen()) m_pCommonRS->Close();
m_pCommonRS->Open(CRecordset::dynaset, strSQL);
if(!m_pCommonRS->IsEOF()){
m_pCommonRS->MoveLast();
m_pCommonRS->MoveFirst();
}
int nFieldCount = m_pCommonRS->GetODBCFieldCount();
CODBCFieldInfo fieldinfo;
for(int n=0;n<nFieldCount;n++){
m_pCommonRS->GetODBCFieldInfo(n, fieldinfo);
int nWidth = ctrlList.GetStringWidth(fieldinfo.m_strName) + 15;
ctrlList.InsertColumn(n, fieldinfo.m_strName, LVCFMT_LEFT, nWidth);
}
// get recordset data information
CString strValue;
m_pCommonRS->MoveFirst();
int nCount = 0; while(!m_pCommonRS->IsEOF()){
ctrlList.InsertItem(nCount, strValue);
for(int j=0;j<nFieldCount;j++){
m_pCommonRS->GetFieldValue(j, strValue);
ctrlList.SetItemText(nCount, j, strValue);
}
m_pCommonRS->MoveNext();
nCount ++;
}
EndWaitCursor();
} catch(CDBException *e){
e->ReportError();
EndWaitCursor();
return FALSE;
} return TRUE;}上面try语句中的第三行m_pCommonRS->Open(CRecordset::dynaset, strSQL);有什么问题吗?程序到那里就不行了。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货