怎么自动配置EXCEL的ODBC呢?
我在CodeBlocks + MinGW中想写一个 自动建立excel的ODBC程序 可是 怎么建立都不正确,每次调用SQLConfigDataSource函数返回都是失败。不知道问题出在哪。
老大们 给小弟指一条明路吧。
char cPathBuf[256];
string sSetOdbcPath;
string sSetFilePath;
bool odbcReturn;
odbcReturn = false;
GetCurrentDirectory(256,cPathBuf);
sSetOdbcPath.assign(cPathBuf);
sSetFilePath = sSetOdbcPath + "\\ItemList.xls?";
sSetOdbcPath = sSetOdbcPath + "?";
sSetOdbcPath.insert(0,"DefaultDir=");
sSetOdbcPath = sSetOdbcPath + "MaxScanRows = 20?";
sSetOdbcPath = sSetOdbcPath + "FristRowHasNames = 1?ReadOnly = False?";
sSetOdbcPath.insert(0,"FIL = Excel 8.0?");
sSetOdbcPath.insert(0,"DBQ=" + sSetFilePath);
sSetOdbcPath.insert(0,"Description = Item Infomation Excel Data Source?");
sSetOdbcPath.insert(0,"DSN = ItemInfo?");
strcpy(cPathBuf,sSetOdbcPath.c_str());
for(int temp = 0;temp < sizeof(cPathBuf);temp++)
{
if('?' == cPathBuf[temp])
cPathBuf[temp] = '\0';
}
cout<<sSetOdbcPath<<endl;
odbcReturn = SQLConfigDataSource(NULL,ODBC_ADD_DSN,
"Microsoft Excel Driver (*.xls)",
cPathBuf);
return 0;