Getting Excel worksheet names with ODBC

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\\Book­1.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,(S­QLCHAR*)"SYSTEM
TABLE",SQL_NTS);
rc = SQLTables(hstmt,0,0,0,0,0,0,(S­QLCHAR*)"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);
 
J

Jens.Toerring

Hello group,
I hope I've come to the right place to post my question!

Sorry, but you didn't. Your question doesn't seem to have to do
anything with the language C, the topic of this group, but seems
to be about some database issues. Therefore you should try to
find a group that deals with this database - looks like it is
something from MicroSoft and there's a huge hierachy of groups
dedicated to the discussion of all kinds of MicroSoft products.
One of them is called <microsoft.public.data.odbc>, perhaps that
one is suitable.
Regards, Jens
 
A

Alan Balmer

Hello group,
I hope I've come to the right place to post my question!
I really can't imagine why you thought a newsgroup about the
(standard) C language would be the right place to post a question
about ODBC and a proprietary spreadsheet program.

Try a Microsoft forum. There are many.
 
W

weboweb

Alan said:
I really can't imagine why you thought a newsgroup about the
(standard) C language would be the right place to post a question
about ODBC and a proprietary spreadsheet program.

Try a Microsoft forum. There are many.

Thank you very much to the both of you.

Cheers
 
C

CBFalconer

I hope I've come to the right place to post my question!

You haven't. You probably need some group with 'Microsoft' in its
name.
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.

The is no ODBC, SQLxxx, etc. mentioned in the C language.
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

There is no file path, worksheet, etc. in the C language. This is
why your query is off-topic here, where we deal with the portable
language, and not specific systems.

--
Some informative links:
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top