请问如何连接sqlserver2000数据库,用adoconnection?
最好有源代码

解决方案 »

  1.   

    //定义
    _RecordsetPtr m_Recordset;
    _CommandPtr m_Commandptr;
    _ConnectionPtr m_pConnection;//连接
    HRESULT hr;
    hr=m_pConnection.CreateInstance("ADODB.Connection");
    if(!SUCCEEDED(hr))
    {
    AfxMessageBox("数据库初始化出错!");
    return false;

    }CString m_username;//用户名
    CString m_password;//密码
    CString m_dbserver; //数据服务器名  
    CString m_dbtable;//数据库名
    CString strConnection = "Provider=SQLOLEDB.1;Data Source=" + m_dbserver + 
    ";Initial Catalog=" + m_dbtable  +
    ";User ID=" + m_username + "; PWD=" + m_password;
    try
    {
    theApp.m_pConnection->Open((_bstr_t)strConnection,"","",-1);
    }
    catch(_com_error e)
    {
    CCommon common;
    AfxMessageBox(common.DisplayAdoError(theApp.m_pConnection));
    }
    try
    {
    m_Commandptr.CreateInstance (__uuidof(Command));
    m_Recordset.CreateInstance (__uuidof(Recordset));

    m_Commandptr->ActiveConnection =theApp.m_pConnection;
    }
    catch(_com_error e)
    {
    CCommon common;
    AfxMessageBox(common.DisplayAdoError(theApp.m_pConnection));
    }
      

  2.   

    源码网上有好多
    直接到www.google.com里search 一下嘛!
      

  3.   

    可以去www.vckbase.com看看,里面好多
    //连接
    HRESULT hr;
    hr=m_pConnection.CreateInstance("ADODB.Connection");
    if(!SUCCEEDED(hr))
    {
    AfxMessageBox("数据库初始化出错!");
    return false;

    }CString m_username;//用户名
    CString m_password;//密码
    CString m_dbserver; //数据服务器名  
    CString m_dbtable;//数据库名
    CString strConnection = "Provider=SQLOLEDB.1;Data Source=" + m_dbserver + 
    ";Initial Catalog=" + m_dbtable  +
    ";User ID=" + m_username + "; PWD=" + m_password;
    try
    {
    theApp.m_pConnection->Open((_bstr_t)strConnection,"","",-1);
    }
    catch(_com_error e)
    {
    CCommon common;
    AfxMessageBox(common.DisplayAdoError(theApp.m_pConnection));
    }
    try
    {
    m_Commandptr.CreateInstance (__uuidof(Command));
    m_Recordset.CreateInstance (__uuidof(Recordset));

    m_Commandptr->ActiveConnection =theApp.m_pConnection;
    }
    catch(_com_error e)
    {
    CCommon common;
    AfxMessageBox(common.DisplayAdoError(theApp.m_pConnection));
    }