VS2005設置Unicode或ASCII字符集問題


在做VC連接數據庫操作時報錯如下:


e:\recv-data\inserttodb\pgdb.cpp(213) : error C2664: 'SQLConnectW' : cannot convert parameter 2 from 'SQLCHAR *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\recv-data\inserttodb\pgdb.cpp(266) : error C2664: 'SQLExecDirectW' : cannot convert parameter 2 from 'SQLCHAR *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\recv-data\inserttodb\pgdb.cpp(284) : error C2664: 'SQLExecDirectW' : cannot convert parameter 2 from 'SQLCHAR *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\recv-data\inserttodb\pgdb.cpp(300) : error C2664: 'SQLExecDirectW' : cannot convert parameter 2 from 'SQLCHAR *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

原因:
VS2005中開發程序時,默認的字符集是Unicode。所以如果程序中使用字符串常量時一定要顯示轉換爲Unicode型,否則編譯時報錯

解決方法:
項目菜單--項目屬性(最後一個)--配置屬性--常規--項目默認值--字符集,將使用Unicode字符集改爲未設置即可。

VS2005設置Unicode或ASCII字符集問題






發佈了29 篇原創文章 · 獲贊 2 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章