My E-mail 用志趣吸引人;用感情留住人;用技術武裝人;用創新發展人;一切以人為本!

Leo LU

程序创建数据源(ODBC)

string GetAppDir(){  
 //获得程序所在路径
 string   szfile;  
 char  szbuffer[200];
 GetModuleFileName(NULL,szbuffer,200); 
 szfile = szbuffer;
 int ipos = szfile.find_last_of("\\");
 szfile = szfile.substr(0,ipos);
 return szfile;
}

EXPORTDLL void configODBC(string szDBName){
 //register ODBC
 string szdir = GetAppDir();
 string szfilepath = szdir + "\\"+szDBName;
 char* szDesc;
 int mlen;
 szDesc=new char[256];
 sprintf(szDesc,"DSN=%s? DESCRIPTION=TOC support source? DBQ=%s? FIL=MicrosoftAccess? DEFAULTDIR=%s?? ",
  "LocatorDB",szfilepath.c_str(),szdir.c_str());
 mlen = strlen(szDesc);
 for (int i=0; i<mlen; i++){
  if (szDesc[i] == '?')
   szDesc[i] = '\0';
 }
 if (FALSE == SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)\0",(LPCSTR)szDesc))
  cout<<"failed"<<endl;
 
}

posted on 2007-08-21 12:02  Leo LU  阅读(184)  评论(0)    收藏  举报

导航