新手求助~~~~~~~~~~~~~~

lizheng197953 2006-11-08 03:23:39
哪位朋友能给我发个vc++用ado连接数据库的完整demo。最好有注释。。。谢谢,我想学习。
leolee19790530@163.com
...全文
146 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
syy64 2006-11-08
  • 打赏
  • 举报
回复
BOOL CDlgDBConnect::ConnectAccess()
{
if(m_strDatabase.IsEmpty())
{
::MessageBox(NULL,"Êý¾Ý¿â²»ÄÜΪ¿Õ£¡","Ìáʾ",MB_OK);
return false;
}
theApp.m_pConnection.CreateInstance(__uuidof(Connection));
try
{
theApp.m_strDatabase=m_strDatabase;
m_strDatabase.Replace("\\","\\\\");
_bstr_t strConn;
if(m_strPassword.IsEmpty())
{

strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +m_strDatabase;
theApp.m_pConnection->CursorLocation = adUseClient;
theApp.m_pConnection->Open(strConn,
"",
"",
adModeUnknown);
}
else
{
strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +m_strDatabase+";Persist Security Info=False;Jet OLEDB:DataBase Password="+m_strPassword;
theApp.m_pConnection->Open(strConn,
"",
"",
adModeUnknown);
}
}
catch(_com_error e)
{
::MessageBox(NULL,e.Description(),"Ìáʾ", MB_OK);
return FALSE;
}

::MessageBox(NULL,"Êý¾Ý¿âÁ¬½Ó³É¹¦£¡","Ìáʾ", MB_OK);
return TRUE;


}
折腾_苏州 2006-11-08
  • 打赏
  • 举报
回复
完整demo+说明

http://www.vckbase.com/document/viewdoc/?id=215
tkd82 2006-11-08
  • 打赏
  • 举报
回复
::CoInitialize(NULL);
_ConnectionPtr pCnn; //连接的数据库指针
HRESULT hr = pCnn.CreateInstance(__uuidof( Connection ));
if(FAILED(hr)) return FALSE;

//connecting to the database server now:
try
{
_bstr_t sConnectStr = "Driver=SQL Server;Database=数据库名;Server=服务器IP;UID=用户名;PWD=密码;";
hr = pCnn->Open(sConnectStr,"","",adModeUnknown);
if( !FAILED(hr) )
bRet = TRUE;
}
catch (_com_error &e)
{
return FALSE;
}
//Exit Now
pCnn->Close();
::CoUninitialize();

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧