在VC++中如何用ADO连接SQL数据库?
展开全部
try
{
m_pCon.CreateInstance(_uuidof(Connection));
m_pCon->Open("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BookManage;Data Source=.\\SQLEXPRESS","","",NULL);
m_pCom.CreateInstance("ADODB.Command");
m_pRs.CreateInstance(_uuidof(Recordset));
m_pRs1.CreateInstance(_uuidof(Recordset));
// ADOFLAG = TRUE;
}
catch(_com_error)
{
//ADOFLAG = FALSE;
Flag = FALSE;
MessageBox(0,"请检查系统配置信息", "数据库连接失败",MB_OK);
return;
}
具体的参数你改改就可以了
{
m_pCon.CreateInstance(_uuidof(Connection));
m_pCon->Open("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BookManage;Data Source=.\\SQLEXPRESS","","",NULL);
m_pCom.CreateInstance("ADODB.Command");
m_pRs.CreateInstance(_uuidof(Recordset));
m_pRs1.CreateInstance(_uuidof(Recordset));
// ADOFLAG = TRUE;
}
catch(_com_error)
{
//ADOFLAG = FALSE;
Flag = FALSE;
MessageBox(0,"请检查系统配置信息", "数据库连接失败",MB_OK);
return;
}
具体的参数你改改就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询