我从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);有什么问题吗?程序到那里就不行了。

解决方案 »

  1.   

    m_pCommonRS->Open(CRecordset::dynaset, strSQL,CRecordset::none);试试
      

  2.   

    m_pCommonRS没有进行数据库字段绑定,只能用CRecordset::snapshot  打开,不能用CRecordset::dynaset打开,如果一定要用CRecordset::dynaset打开,要从crecordset 派生一新类,绑定数据库字段就行了
      

  3.   

    但我的CCommonRs就是从CRecordset派生出来的呀
      

  4.   

    你不能详细的吗,ShowInformation()是什么东东?出什么问题?
      

  5.   

    kaka ,我知道是什么咚咚,是一本教程的例子,这个例子程序没错,也许是你的数据表和你的派生类绑定的时候出错了
      

  6.   

    你在调用Open()函数时,有没有将CString类型的sql转化成_bstr_t呢?