0

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

尽管我的表中有 20 列,但它会打印0如何修复查询或逻辑?

4

1 回答 1

1

我认为这篇 MSDN 文章中的示例会有所帮助:如何:在各种字符串类型之间进行转换

引用文章:

涵盖的字符串类型包括 char *、wchar_t*、_bstr_t、CComBSTR、CString、basic_string 和 System.String。

转换_bstr_twchar_t*char*然后使用strtol()/wcstol()将其转换为long.

于 2011-07-16T16:34:55.930 回答