A blank string instead of the actual number is returned when selecting from an Excell sheet.

J

Joakim Olesen

Hi

I have an issue with an asp page that reads from an Excel file. I read the
file using OLEDB. I create a new Excel file using "MS Excel 2003" and put
the following data into a sheet called "Ark1" (2 columns and 5 rows):

1234 reer
1234 feb
4467 heerh
4467 123123
1122 234561122


Then I save the sheet and open an ASP page that has the following code:

Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath &
";Extended properties=""Excel 8.0;HDR=NO;"""
set rs = conn.Execute("Select * FROM [Ark1$]")
while not rs.eof
response.write("<br>" & rs(0) & " : " & rs(1))
rs.movenext
wend


And this is the result (with HTML code):
<br>1234 : reer<br>1234 : feb<br>4467 : heerh<br>4467 : <br>1122 :

If I replace <br> with a line-break, the result looks like this:
1234 : reer
1234 : feb
4467 : heerh
4467 :
1122 :


As you can see, las two iterations doesn't print the rs(1)) correctly.
Instead of printing the correct value, only a blank string is printed.
Initially I didn't make any formatting in the Excel sheet at all, but
formatting all columns in the sheet as "text" didn't help.

I've made several test files with random data in the two columns. It always
works fine when there is at least one none-digit character in the fields,
but when there are only numeric characters, it sometimes displays correctly,
and sometimes doesn't. The numbers in the first column also disappears
sometimes, it's not only the numbers in the second row.


Could you please help me with this issue? Thanks in advance.
 
R

Ray Costanzo [MVP]

Hi Joakim,

Add IMEX=1 to your connection string so it looks like so:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & ";Extended
properties=""Excel 8.0;HDR=NO;"""

That tells ADO to just treat everything as text.

Ray at work
 
R

Ray Costanzo [MVP]

Oops. I forgot to modify the connection string. 8|

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & ";Extended
properties=""Excel 8.0;HDR=NO;IMEX=1"""

Ray at work
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top