ado连数据库

来源:互联网 发布:linux exec 3>命令 编辑:程序博客网 时间:2024/06/10 16:46

 m_pConnection.CreateInstance("ADODB.Connection");
  _bstr_t strConnect = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=USERINFO;Data Source=ADMINADM-C37D9\\SQLEXPRESS";
  /*
  Provider=SQLOLEDB.1:数据库驱动版本
  Integrated Security=SSPI:以Windows用户身份登陆数据库。
  Persist Security Info=False:Integrated Security默认值是False,此时需要提供Uid和Pwd。
  但前面Integrated Security的值为SSPI,因此不能出现Uid和Pwd。
  Initial Catalog=图书后台管理:所要连接的数据库。
  Data Source=.:数据源本地连接。
  */

 

//////////////////////////////////////////

CComBSTR,但在程序中要将返回值转为CString,查了好多资料都是用comutil.h中的ConvertBSTRToString(),但是用后发现中文为乱码。最后发现CComBSTR可以转为&BSTR,这下就有办法了,用最简单的方法就可以转了:
   CString str((LPCTSTR)BSTR)

原创粉丝点击