我正在使用 Visual Studio 2008 和 SQL Server,目前我有一个使用 ADO 的连接,但想检索一个表具有的列数...
这是我的
/*CODE FOR connecting to database**/
/*query to know number of columns in table*/
_bstr_t sSQLd="Select Count(*) From INFORMATION_SCHEMA.COLUMNS Where TABLE_NAME='[dbo].[mytable]';";
/*define variable to hold number of columns and
print number of coulms as an integer
*/
int COLS_PER_ROW = wcstod(sSQLd, NULL);
printf("COLS_PER_ROW: %d", COLS_PER_ROW);
它打印 0
尽管我的表中有 20 列
如何修复查询或逻辑??
最佳答案
我认为这篇 MSDN 文章中的示例会有所帮助:How to: Convert Between Various String Types
文章引用:
The strings types that are covered include char *, wchar_t*, _bstr_t, CComBSTR, CString, basic_string, and System.String.
从_bstr_t
转换为wchar_t*
或char*
然后使用strtol()/wcstol()
将其转换为 long
。
关于c++ - 使用 _bstr_t 和 ADO 在 C++ 中获取列数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6718572/