//主要代码如下。 用的是ADO方法
::CoInitialize(NULL);
    try
    {
        HRESULT hr;
        m_pConnection.CreateInstance("ADODB.Connection");
        _bstr_t ConStr="Provider=SQLOLEDB;Password=;Persist Security Info=false;User ID=sa;Initial Catalog=data;Data Source=127.0.0.1";//请各位高手看看此处有没有不妥的地方,我就是这里搞不懂应该怎样填写才正确。 
        hr=m_pConnection->Open(ConStr,"","",NULL);
        if(SUCCEEDED(hr))
        {
            AfxMessageBox("success");
            m_pRecordset.CreateInstance(__uuidof(Recordset));
            _bstr_t vSQL;
            vSQL="select * from student";
            m_pRecordset->Open(vSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
            m_pRecordset->MoveFirst();
            CString username;
            username=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("name");
            AfxMessageBox(username);
        }
        else
            AfxMessageBox("断开连接");
        m_pConnection->Close();
    }
    catch(_com_error e)
    {
        AfxMessageBox(e.ErrorMessage());
        AfxMessageBox(e.Description());
        AfxMessageBox(e.Source());
    }
    CoUninitialize();
运行结果:提示说用户sa连接不到数据库。我就不知道该怎么办了。
是不是在计算机上还要设置一些什么连接????要设置ODBC数据源还是怎么着?
谢谢!!!