void CTestremotedataDlg::OnConnect() 
{
                                
    // TODO: Add your control notification handler code here
    _ConnectionPtr  m_pConnection;
    // 初始化COM,创建ADO连接等操作
    try
    {
        HRESULT hr=m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
        if(SUCCEEDED(hr))
        {
            hr=m_pConnection->Open("DSN=test1;"/*数据源名称*/,
                "",/*用户*/
                "",/*密码*/-1);//连接数据库
            if(m_pConnection->State)
            {    AfxMessageBox("Connecting is succeed!");}
        }
    }
    
    catch(_com_error e)
    {
        AfxMessageBox("数据库连接失败,确认数据库Demo.mdb是否在当前路径下!");
    }      
    //连接数据库成功
    _RecordsetPtr    m_Recordset;
     m_Recordset.CreateInstance("ADODB.Recordset"); 
    
    // 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
    // 因为它有时会经常出现一些意想不到的错误。jingzhou xu
    try
    {
        m_Recordset->Open("select*from sheet1", m_Recordset.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText    );这个获得记录集对象老是失败
    if(m_Recordset->State)
    {
    AfxMessageBox("Recordset succeed!");//
    }
    }
    catch(_com_error e)
    {
        AfxMessageBox("Recordset failed!");
    }     
    
}
ado 访问access数据库,数据源test1,表格sheet1;
初始化com都在前面的    Initstance()函数中做过了
这个获得记录集对象老是失败,连接数据库都对了成功了,但是获得记录集对象老是失败!
请大家看看怎么回事,在线等!

											
	    
