問題分析好久,
經(jīng)過排查,問題在于數(shù)據(jù)庫的啟動(dòng)路徑有問題,在連接數(shù)據(jù)庫 時(shí)候可以這樣寫
GetModuleFileName(NULL,path,255);//獲得自啟動(dòng)的程序完整路徑;
CString str;
str.Format("%s",path);
int place;
place = str.ReverseFind( '\\' ); //獲得最后一個(gè)'\'的位置;
CString db_name;
db_name = str.Left(place+1) + "qijian.mdb"; //整合出access數(shù)據(jù)庫完整路徑
CString connect; //連接的第一個(gè)參數(shù)
connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db_name + ";";
hr = theApp.m_pConnection->Openconnect.GetBuffer(connect.GetLength()),"","",adModeUnknown); //參數(shù)帶入并連接
其余代碼不必多改 .
更多信息請(qǐng)查看IT技術(shù)專欄