Getting Excel worksheet names with ODBC

Discussion in 'C Programming' started by weboweb@hotmail.com, May 26, 2005.

  1. Guest

    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);
    , May 26, 2005
    #1
    1. Advertising

  2. -berlin.de Guest

    wrote:
    > 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
    --
    \ Jens Thoms Toerring ___ -berlin.de
    \__________________________ http://www.toerring.de
    -berlin.de, May 26, 2005
    #2
    1. Advertising

  3. Alan Balmer Guest

    On 26 May 2005 05:58:05 -0700, wrote:

    >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.

    --
    Al Balmer
    Balmer Consulting
    Alan Balmer, May 26, 2005
    #3
  4. Guest

    Alan Balmer wrote:
    > On 26 May 2005 05:58:05 -0700, wrote:
    >
    > >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.
    >
    > --
    > Al Balmer
    > Balmer Consulting
    >


    Thank you very much to the both of you.

    Cheers
    , May 26, 2005
    #4
  5. CBFalconer Guest

    wrote:
    >
    > 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:
    news:news.announce.newusers
    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
    CBFalconer, May 26, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. harshan
    Replies:
    0
    Views:
    523
    harshan
    Jul 20, 2004
  2. =?Utf-8?B?U2hhbyBZb25n?=

    How to delete an Excel worksheet by using ASP.NET?

    =?Utf-8?B?U2hhbyBZb25n?=, May 10, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    1,138
    Martin Dechev
    May 12, 2004
  3. Barbara Vernaeve

    POI HSSF generate 2nd excel worksheet.

    Barbara Vernaeve, Feb 1, 2005, in forum: Java
    Replies:
    0
    Views:
    565
    Barbara Vernaeve
    Feb 1, 2005
  4. Replies:
    1
    Views:
    295
    Mirco Wahab
    Apr 17, 2007
  5. Katja
    Replies:
    1
    Views:
    214
Loading...

Share This Page