c++ - 使用 _bstr_t 和 ADO 在 C++ 中获取列数

标签 c++ visual-studio sql-server-2008 bstr-t

我正在使用 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/

相关文章:

mysql - 将 J2EE 应用程序与两个不同的数据库连接

SQL:从表中获取最新的(未)订阅操作

database - 查找存储过程的参数名称

c++ - CComSafeArray MultiDimSetAt 是否制作引用元素的拷贝?

c++ - 无法从我的静态库 C++ VS 打开 boost header

c++ - 批评我的非侵入式堆调试器

c# - 监控tcp数据

c++ - 如何在我的 Qt 应用程序中处理 "Project Files"?

C++ VS 调试器转移行为?

visual-studio - 尝试构建项目时如何修复 'Schema validation error'?