(1)CADORecordset  m_Rs            (ADO方式访问数据库)  
(2)数据表stu及"score"字段  
(3)打开stu表  
           m_Rs.Open("SELECT  *  FROM  stu");  
(4)统计stu中满足"score>60"的记录个数,代码怎样写?VC下怎样用代码访问这个统计值?  
 
 
ps:  msdn给出如下sql语句格式,但vc下该如何使用?  
    SELECT  Count(Amount)  AS  [Number  of  Valid  Invoice  Amounts]  FROM  tblInvoices

解决方案 »

  1.   

    m_Rs.Open("SELECT count(*) as abc FROM  stu where score>60");
      

  2.   

    还可以这样:
    int counter=0;
    m_Rs.Open("SELECT  *  FROM  stu where score>60");
    m_Rs.MoveFirst;
    while(!m_Rs->adoEOF)
    {
       counter++;
    }
    CString output;
    output.Format("共找到%d条记录!",counter);
    AfxMessageBox(output);
      

  3.   

    就一楼的方法就可以了,二楼的麻烦了,其实像这种直接ODBC API多简单,还要用CDatabase/CRecordSet,哎。
      

  4.   

    看看这个类有没有GetRecordCount函数可用
      

  5.   

    m_Rs.Open("SELECT *  FROM  stu where score>60");
    int counter=m_Rs.GetRecordCount();
      

  6.   

    open之后
    int count=m_Rs。GetFetchedRows();
      

  7.   

    请问m_Rs.Open("SELECT count(*) as abc FROM  stu where score>60");
    abc是什么变量,又怎么读出来?