我在VC++6.0写了个数据库程序。我在网上搜了,都不行。
sql = "Select * from Mytable";
Mytable里有许多的数据,(不过有些字段没有写数据).
bool ADOConn::MoveFirst ()
{
int ncount = this->m_pRecordset->GetRecordCount();
try

                  // 这个if怎么写都不行啊
  if(!this->m_pRecordset->adoEOF||!this->m_pRecordset->adoBOF)   
this->m_pRecordset->MoveFirst ();
}
catch (_com_error e)
{
AfxMessageBox (e.Description () ); return false;
} return true;
}
为什么总是说“OF和BOF有一个为真“的错误啊?我怎么处理数据库里面的空数据呢?因为我要把数据写到ListControl里面。
我找一个上午了,谢谢了各位,我一定给分。(就是数据库里为空,怎么处理啊)

解决方案 »

  1.   

    在你的MoveFirst()里不要判断adoEOF 
      

  2.   

    int ncount = this- >m_pRecordset- >GetRecordCount(); 
    那 ncount 怎么老是返回为-1啊?明明是有许多的数据的啊。
      

  3.   

    如果 ADO 无法确定记录数目或者提供者或游标类型不支持 RecordCount,该属性将返回 -1
      

  4.   

    我的open是这样写的:
    m_pRecordset->Open (bstrSQL, this->m_pConnection.GetInterfacePtr(), adOpenDynamic, 
    adLockOptimistic, adCmdText);
      

  5.   

    去掉一半呢
    只留下eof或者bof
      

  6.   

    to 亲爱的 我是菜鸟:
    “去掉一半呢 
    只留下eof或者bof”
    这个我也试过了,只是我的数据里有些脏数据(就是在某些字段里,没有数据)。我该怎么办?
      

  7.   

    某些字段没有数据用eof和bof判断不出来吧
    在where里面过滤呢?
    或者取出来判断GetCollect("字段名").vt==VT_NULL
      

  8.   

    to 大毛
    我试了也不行,
    to 我是菜鸟
    我的 m_pRecordset-  >GetRecordCount(),就为-1啊。没有用GetCollect()。
      

  9.   

    m_pRecordset->CursorLocation = adUseClient;
      

  10.   

    _RecordsetPtr &ADOConn::GetRecordSet (_bstr_t bstrSQL)
    {
    try
    {
    // connect database, IF Connection is NULL, THEN Resume
    if( m_pConnection == NULL)
    this->OnInitDBConnect(); // Create Recordset Object
    m_pRecordset.CreateInstance (__uuidof(Recordset)); m_pRecordset->CursorLocation = adUseClient;
    // Get Record in TABLE
    m_pRecordset->Open (bstrSQL, m_pConnection.GetInterfacePtr(),adOpenDynamic, 
    adLockOptimistic, adCmdText); }
    // catch UNNormal
    catch( _com_error e)
    {
    // Display error INFORMATION
    AfxMessageBox (e.Description());
    }
    int count = this->m_pRecordset->GetRecordCount();//在这个地方,得到0值啊。
    // Return Recordset
    return this->m_pRecordset;}
      

  11.   


    各位,是我错了。
    对不起了。我用的是EXCEL文件,我没有选择所有的数据,所以有不存在的数据。
    我每个人都给分,除我自己外。谢谢各位了。