在“管理工具”----“資料來源”設定DSN
#pragma once#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers#include <stdio.h>#include <tchar.h>//使用#import把動態串連庫msado15.dll匯入,組建定義ADO庫的兩個C++標頭檔:msado15.tlh和ado15.tli#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "EndOfFile")void main(){char *sqlCommand = "insert into student values (20120822,'C++conect'); ";_bstr_t strConnect = "DSN=mysql5;Database=test;uid=root;pwd=890531;";//初始化COM庫::CoInitialize(NULL);//添加一個指向Connection對象的指標m_pConnection_ConnectionPtr m_pConnection(__uuidof(Connection));//創鍵Connection對象if(FAILED(m_pConnection.CreateInstance(__uuidof(Connection)))) {printf("創鍵Connection對象時出錯\n");}try{//串連資料庫m_pConnection->Open(strConnect,"","",adModeUnknown); }catch(_com_error e) {printf("串連資料庫時出錯\n");}m_pConnection->Execute(sqlCommand, NULL, 1);//執行SQL語句m_pConnection->Close(); //釋放程式佔用的COM 資源::CoUninitialize(); }
資料是插進去了,但是有錯誤
Error in my_thread_global_end(): 1 threads didn't exit
不知道咋回事,在網上搜了一下,說是mysql的問題。。。。求高手幫忙