vs2005连接sqlserver2005(C++)

#include
#include
#include
#include
#import "c:\Program Files\Common Files\System\ADO\msado15.dll"  no_namespace rename("EOF", "adoEOF")
using namespace std;
int main()
{

 
 CoInitialize(NULL);
 _RecordsetPtr m_pRecordset("ADODB.Recordset");
 _ConnectionPtr m_pConnection("ADODB.Connection");
 _bstr_t bstrSQL("select * from Tstudent;");
 
 
 m_pConnection.CreateInstance("ADODB.Connection");
 _bstr_t strConnect= "Provider=SQLOLEDB;Server=localhost;Database=mydatabase;uid=sa; pwd=admin";

 m_pConnection->Open(strConnect,"","",adModeUnknown);
 
 if(m_pConnection==NULL)
  printf("conn error");
 
 printf("conn ok\n");
 system("pause");
 return 0;

}

你可能感兴趣的:(数据库,c/c++)