Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / April 2007



Tip: Looking for answers? Try searching our database.

NULL-Values instead of integer-values while reading from excel

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jan Lorenz - 19 Apr 2007 14:38 GMT
Hi,

i read a excel-file via ado. It works fine, when text is in the cells. When
there is a integer-value (f.i. 1234), then I always get NULL. When I write
'1234 in the cell, then it works also.

My code is:

Set CN = New ADODB.Connection
CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Path
& ";Extended Properties=Excel 8.0; HDR=No;"
CN.CursorLocation = adUseClient
CN.Open
Set RS = New ADODB.Recordset
sql = "SELECT  * FROM [" + SheetName + "]"
RS.Open sql, CN, adOpenStatic, adLockOptimistic
a = RS.Fields(0).Value......

Any tip?

best regards
Jan
Paul Clement - 20 Apr 2007 15:07 GMT
¤ Hi,
¤
¤ i read a excel-file via ado. It works fine, when text is in the cells. When
¤ there is a integer-value (f.i. 1234), then I always get NULL. When I write
¤ '1234 in the cell, then it works also.
¤
¤ My code is:
¤
¤ Set CN = New ADODB.Connection
¤ CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Path
¤ & ";Extended Properties=Excel 8.0; HDR=No;"
¤ CN.CursorLocation = adUseClient
¤ CN.Open
¤ Set RS = New ADODB.Recordset
¤ sql = "SELECT  * FROM [" + SheetName + "]"
¤ RS.Open sql, CN, adOpenStatic, adLockOptimistic
¤ a = RS.Fields(0).Value......
¤
¤ Any tip?

This is because you have a mixed mode column (string and numeric data). Try adding the IMEX argument
to your connection string so that the data is imported properly:

cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  "Data Source=" & Path  & ";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"""

Paul
~~~~
Microsoft MVP (Visual Basic)
Jan Lorenz - 20 Apr 2007 15:13 GMT
thanks a lot. It works.

> ¤ Hi,
> ¤
[quoted text clipped - 30 lines]
> ~~~~
> Microsoft MVP (Visual Basic)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.