+ Reply to Thread
Results 1 to 5 of 5

How to read the column which include text and number in the excel via ODBC?

  1. #1
    Registered User
    Join Date
    08-10-2008
    Location
    China
    Posts
    24

    How to read the column which include text and number in the excel via ODBC?

    Hi everyone,

    Who can tell me how to read the column which include text and number in the excel via ODBC?
    like one columnA include 'abcd'(Text) and 1234(number)
    I want to read all the data in columnA, but seems that I can only read the data which the datatype is consistent with the begining of the data in the column.
    For example. (please correct me if anything is wrong)
    If the begining of the data are 'adcd', 'dfd-yrtd','yreh4645', the data type in this column was defined as text by default, and then I can't read the numeric data in this column if there is numeric (like 1123) data in the column.

    I use the sql like: select * from ...
    So I think I should read all the data in this column.


    Thanks
    Winnie

  2. #2
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388
    Use IsNumeric to test if the text can be converted to a number and Val to return the number.
    This little demo shows how:
    Please Login or Register  to view this content.
    The only numbers output are 1, 0 and 1234.

  3. #3
    Registered User
    Join Date
    08-10-2008
    Location
    China
    Posts
    24
    Thanks for you reply.

    I just want to query the data in the attachment by using the following quey in MSQuey. but seems that I can't read the numeric data which is "123" and "456". I think the begining of the row is string I input, right? If so, how to work around it?
    testquey.xls
    query:
    SELECT `Sheet1$`.`No#`, `Sheet1$`.Name FROM `C:\testquey`.`Sheet1$` `Sheet1$`


    Thanks
    Winnie

  4. #4
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388
    Please read this MS Support article How To Use ADO with Excel Data from Visual Basic or VBA

    In the section A Caution about Mixed Data Types
    2 possible workarounds are given; either store numerics as text or use the setting "IMEX=1" in the connection string.

    As a result, if your column contains mixed values, your only recourse is to store numeric values in that column as text, and to convert them back to numbers when needed in the client application by using the Visual Basic VAL function or an equivalent.
    To work around this problem for read-only data, enable Import Mode by using the setting "IMEX=1" in the Extended Properties section of the connection string.

  5. #5
    Registered User
    Join Date
    08-10-2008
    Location
    China
    Posts
    24
    That is very useful info, Now I can read the data no matter which datatype it is. Thanks a lot ^_^

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1