W
weboweb
Hello group,
I hope I've come to the right place to post my question!
I am trying to get the worksheet names from an excel file using ODBC,
but for some reason I get SQL_NO_DATA error code instead (100)
This code snippet I got from an example I found somewhere, and I want
to use this logic in a more complex program.
I'm hard-coding the file path for this example. This particular
spreadsheet contains 3 worksheets (Sheet1, Sheet2, Sheet3)
I've tried with many other spreadsheets but I can't seem to get the
worksheet names. I've also tried the "SYSTEM TABLE" and "TABLE" in the
SQLTables called with no luck.
Would somebody please point me in the right direction as to what I'm
doing wrong here?
Thanks!
WebOWeb
SQLHENV henv = NULL;
SQLHDBC hdbc = NULL;
SQLHSTMT hstmt = NULL;
char dsn[] = "Driver={Microsoft Excel Driver
(*.xls)};Dbq=C:\\nestemp\\Book1.xls";
SQLTCHAR outdsn[1024];
SQLSMALLINT outdsnlen;
SQLAllocHandle(SQL_HANDLE_ENV, NULL, &henv);
SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3,
SQL_IS_INTEGER);
SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
int rc = SQLDriverConnect(hdbc, NULL, (SQLTCHAR*)dsn,
strlen(dsn),outdsn, sizeof(outdsn), &outdsnlen, SQL_DRIVER_NOPROMPT);
if(rc==SQL_SUCCESS)
{
printf("OUT: %s\n",outdsn);
SQLAllocHandle(SQL_HANDLE_STMT, hdbc,&hstmt);
//rc = SQLTables(hstmt,0,0,0,0,0,0,(SQLCHAR*)"SYSTEM
TABLE",SQL_NTS);
rc = SQLTables(hstmt,0,0,0,0,0,0,(SQLCHAR*)"TABLE",SQL_NTS);
if(rc==SQL_SUCCESS)
{
printf("SQLTables OK\n");
while(SQLFetch(hstmt)==0) //SQL_NO_DATA over here
{
printf("sheet found\n",rc);
}
}
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
}
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_ENV, henv);
I hope I've come to the right place to post my question!
I am trying to get the worksheet names from an excel file using ODBC,
but for some reason I get SQL_NO_DATA error code instead (100)
This code snippet I got from an example I found somewhere, and I want
to use this logic in a more complex program.
I'm hard-coding the file path for this example. This particular
spreadsheet contains 3 worksheets (Sheet1, Sheet2, Sheet3)
I've tried with many other spreadsheets but I can't seem to get the
worksheet names. I've also tried the "SYSTEM TABLE" and "TABLE" in the
SQLTables called with no luck.
Would somebody please point me in the right direction as to what I'm
doing wrong here?
Thanks!
WebOWeb
SQLHENV henv = NULL;
SQLHDBC hdbc = NULL;
SQLHSTMT hstmt = NULL;
char dsn[] = "Driver={Microsoft Excel Driver
(*.xls)};Dbq=C:\\nestemp\\Book1.xls";
SQLTCHAR outdsn[1024];
SQLSMALLINT outdsnlen;
SQLAllocHandle(SQL_HANDLE_ENV, NULL, &henv);
SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3,
SQL_IS_INTEGER);
SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
int rc = SQLDriverConnect(hdbc, NULL, (SQLTCHAR*)dsn,
strlen(dsn),outdsn, sizeof(outdsn), &outdsnlen, SQL_DRIVER_NOPROMPT);
if(rc==SQL_SUCCESS)
{
printf("OUT: %s\n",outdsn);
SQLAllocHandle(SQL_HANDLE_STMT, hdbc,&hstmt);
//rc = SQLTables(hstmt,0,0,0,0,0,0,(SQLCHAR*)"SYSTEM
TABLE",SQL_NTS);
rc = SQLTables(hstmt,0,0,0,0,0,0,(SQLCHAR*)"TABLE",SQL_NTS);
if(rc==SQL_SUCCESS)
{
printf("SQLTables OK\n");
while(SQLFetch(hstmt)==0) //SQL_NO_DATA over here
{
printf("sheet found\n",rc);
}
}
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
}
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_ENV, henv);