现在打开了access数据源Student.mdb。
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Student.mdb","","",adModeUnknown);
想要通过按钮的消息函数将此数据源断开,变换到Student2.mdb数据源,应该如何通过ADO实现。
谢谢。

解决方案 »

  1.   

    自定义一个消息,当btn click 得时候,sendmessage,postmessage,消息处理函数中,关闭m_pConnectin,然后重新打开新得
      

  2.   

    能不能提供详细的代码,:)
    我在消息处理函数中是这样实现的,但是报告“数据库连接失败,确认数据库Student2.mdb是否在当前路径下!”
    十分感谢!
    // 关闭记录集
    m_pRecordset->Close();
    m_pRecordset = NULL;
    if(::theApp.m_pConnection->State)
    ::theApp.m_pConnection->Close();
    ::theApp.m_pConnection = NULL;
    try                 
    {
    // 打开本地Access库Student.mdb
    ::theApp.m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Student2.mdb","","",adModeUnknown);

    }
    catch(_com_error e)
    {
    AfxMessageBox("数据库连接失败,确认数据库Student2.mdb是否在当前路径下!");
    return;
    }
      

  3.   

    当然在当前目录下了,
    在想,是不是不能用同样的语句连接呢?
    ::theApp.m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Student2.mdb","","",adModeUnknown);
    还是另外有什么语句?
      

  4.   

    搞定了,原来不能加m_pRecordset = NULL;::theApp.m_pConnection = NULL;语句。
    好高兴啊
      

  5.   

    来晚了,呵呵。
    m_pRecordset = NULL;::theApp.m_pConnection = NULL
    把对象都释放了,肯定不能再连接了。
    只要Close就可以。