我用下面的方式打开数据库:
                try
                {
                    CString ConnectString="ODBC;DSN=gmcc;UID=sa;PWD=;DATABASE=gmcc_mis";
                    m_database=new CDatabase;
                    if(!m_database->Open(NULL,FALSE,FALSE,ConnectString,FALSE))
                    {
                        AfxMessageBox("ODBC Connection Faile!");
                        //CDialog::EndDialog(0);
                        //GetParent()->PostMessage(WM_CLOSE);
                        return;
                    }
然后,取数据用CRecordset:
                    CString strSQL;
                    char str[256];
                    sprintf(str,"select * from mis_loguser where intime>='%s' and intime<='%s' order by callid",usertimestart,usertimeend);
                    strSQL=str;
                    m_pSet=new CRecordset(m_database);
                    //CRecordset m_pSet(&m_database);
                    m_pSet->Open(CRecordset::forwardOnly,strSQL);
                    
                    if(isEmpty())
                    {
                        //SetNoRecordBtnState();
                        AfxMessageBox("数据库中没有数据!");
                        return;
                    }
在循环取CRecordset的数据当中,碰到了一个问题,当第二次运行到m_pSet->MoveNext时,就进到汇编里去了,怎么办?
                    while(!m_pSet->IsEOF() )
                    {


                        // 移到下一行
                        m_pSet->MoveNext();
                    }
完整的程序在下边:
    CString temp1;
    CString temp2;    char usertimestart[15];
    char usertimeend[15];
    int pertime;
    int len1,len2;
    BOOL flag;
    count=0;
    pertime=0;
    totaltime=0;
    totalprice=0.0;
    usernum=0;
    excelflag=FALSE;
    flag=TRUE;    if(UpdateData()==TRUE)
    {
        sprintf(usertimestart,"%s",m_usertimestart);
        sprintf(usertimeend,"%s",m_usertimeend);
        len1=strlen(usertimestart);
        len2=strlen(usertimeend);
        if(len1!=14||len2!=14)
        {
            AfxMessageBox("时间格式不正确!请重新输入!");
            return;
        }
        else if(usertimestart<usertimeend)
        {
            AfxMessageBox("错!开始时间应该比结束时间早!请重新输入!");
            return;
        }
        else{                usertimestart[15]='\0';
                usertimeend[15]='\0';
                tempTimeStart=usertimestart;
                tempTimeEnd=usertimeend;
                
                try
                {
                    CString ConnectString="ODBC;DSN=gmcc;UID=sa;PWD=;DATABASE=gmcc_mis";
                    m_database=new CDatabase;
                    if(!m_database->Open(NULL,FALSE,FALSE,ConnectString,FALSE))
                    {
                        AfxMessageBox("ODBC Connection Faile!");
                        //CDialog::EndDialog(0);
                        //GetParent()->PostMessage(WM_CLOSE);
                        return;
                    }
                    
                    CString strSQL;
                    char str[256];
                    sprintf(str,"select * from mis_loguser where intime>='%s' and intime<='%s' order by callid",usertimestart,usertimeend);
                    strSQL=str;
                    m_pSet=new CRecordset(m_database);
                    //CRecordset m_pSet(&m_database);
                    m_pSet->Open(CRecordset::forwardOnly,strSQL);
                    
                    if(isEmpty())
                    {
                        //SetNoRecordBtnState();
                        AfxMessageBox("数据库中没有数据!");
                        return;
                    }
                    m_pSet->GetFieldValue("callid", temp1);
                    sprintf(userid,"%s",temp1);
                    userid[11]='\0';
                    while(!m_pSet->IsEOF() )
                    {
                        CString temp;
                        char tempID[12];
                        int temptime;
                        
                        if(flag==FALSE)
                        {
                            m_pSet->GetFieldValue("callid",temp);
                            sprintf(tempID,"%s",temp);
                            tempID[11]='\0';
                        }
                        else
                        {
                            sprintf(tempID,"%s",userid);
                            flag=FALSE;
                        }
                        
                        if(MyCompareStr(tempID,userid))
                            count=count+1;
                        else
                        {
                            UpdateOrder(userid,pertime,count);
                            usernum=usernum+1;
                            totaltime=totaltime+pertime;
                            totalprice=totalprice+0.6*pertime;
                            count=1;
                            pertime=0;
                            flag=TRUE;
                            sprintf(userid,"%s",temp);
                        }
                        temptime=GetUserValue(m_pSet);
                        pertime=pertime+temptime;
                        // 移到下一行
                        m_pSet->MoveNext();
                    }    
                    m_pSet->Close();
                    m_database->Close();
                    tempTimeStart=" ";
                    tempTimeEnd=" ";
                    delete m_pSet;
                    delete m_database;
                }
                catch(CDBException* pEx)
                {
                    pEx->ReportError();
                } 
        }
    }