I am using Visual Studio 2008, and SQL Server, Currently I have a connection using ADO, but would like to retrieve the number of columns a table has...
Here is what I have
/*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);
It prints 0
although There are 20 columns in my table
How do I fix the query or the logic??
I think the examples in this MSDN article will help: How to: Convert Between Various String Types
Quoting from the article:
The strings types that are covered include char *, wchar_t*, _bstr_t, CComBSTR, CString, basic_string, and System.String.
Convert from _bstr_t
to wchar_t*
or char*
and then use strtol()/wcstol()
to convert it to long
.