HRESULT hr;
try
{
hr=m_pConnect.CreateInstance("ADODB.Connect");
if(SUCCEEDED(hr))
{
hr=m_pConnect->Open(_bstr_t("Provider=SQLOLEDB;sever=WIN-S5HIEH7BODB\SQL_User;database=User;"),_bstr_t("sa"),_bstr_t("123456"),-1);
}///求解!!!!!!!!!!!!!!!!
}
catch(_com_error e)
{
CString error;
error.Format("连接数据库失败!\r\n错误信息:%s",e.Error());
AfxMessageBox(error);
}
//连接成功了,但查询时有问题!!!void CADODlg::OnOK() 
{
// TODO: Add extra validation here

//::CoInitialize(NULL);_variant_t((IDispatch *)m_pConnect,true),
m_pRecord.CreateInstance("ADODB.Recordset"); //创建一个实例
try{ //m_pRecord->Open("Select  * from student ", m_pConnect.GetInterfacePtr(),adOpenDynamic,   
//adLockOptimistic,adCmdText);
//MessageBox("Hello");
}
catch (_com_error e)
{
CString error;
error.Format("连接数据库失败!\r\n错误信息:%s",e.Error());
AfxMessageBox(error);
}

CDialog::OnOK();
}