473,667 Members | 2,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

read excelfile with ADO

Hello,

I'm using ADO to read an excelfile in a datagrid as follows:

Dim cnn As NewOleDb.OleDbC onnection("Prov ider=Microsoft. Jet.OLEDB.4.0;
Data Source=" & filename & ";Extended Properties=""Ex cel
8.0;HDR=YES;""" )
Dim da As New OleDb.OleDbData Adapter("Select * from [Sheet1$]", cnn)
Dim dt As New DataTable("exce l")
da.Fill(dt)
Datagrid1.datas ource = dt
This works fine. But when a certain column on the second row (the first
row are the headers) contains an integer, then ADO assumes that this
whole column contains integers (except for the header offcourse). And
for each value that is not an integer, ADO replaces the string with the
DBNull value.

What am I doing wrong? Or is this a known bug? Are there any workarounds?

Thanks for the help,

Steven
Mar 24 '06 #1
2 1093
Steven,

Here is a url that explains your options:

http://www.sqldts.com/default.aspx?254

Kerry Moorman
"steven" wrote:
Hello,

I'm using ADO to read an excelfile in a datagrid as follows:

Dim cnn As NewOleDb.OleDbC onnection("Prov ider=Microsoft. Jet.OLEDB.4.0;
Data Source=" & filename & ";Extended Properties=""Ex cel
8.0;HDR=YES;""" )
Dim da As New OleDb.OleDbData Adapter("Select * from [Sheet1$]", cnn)
Dim dt As New DataTable("exce l")
da.Fill(dt)
Datagrid1.datas ource = dt
This works fine. But when a certain column on the second row (the first
row are the headers) contains an integer, then ADO assumes that this
whole column contains integers (except for the header offcourse). And
for each value that is not an integer, ADO replaces the string with the
DBNull value.

What am I doing wrong? Or is this a known bug? Are there any workarounds?

Thanks for the help,

Steven

Mar 24 '06 #2
Thank you very much !! Just adding "IMEX=1" to my connectionstrin g did
the job!!

Steven

Kerry Moorman schreef:
Steven,

Here is a url that explains your options:

http://www.sqldts.com/default.aspx?254

Kerry Moorman

Mar 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
11650
by: Steven T. Hatton | last post by:
I know of a least one person who believes std::ifstream::read() and std::ofstream::write() are "mistakes". They seem to do the job I want done. What's wrong with them. This is the code I currently have as a test for using std::ifstream::read(). Is there anything wrong with the way I'm getting the file? #include <vector> #include <iomanip> #include <fstream> #include <iostream>
1
3992
by: Jose Reckoner | last post by:
I'm running python 2.3 on Windows XP. Anyone have a quick small script to convert .DT1 and .DEM data to ASCII or some other format? I don't need a viewer. Thanks!
5
43422
by: barbara_dave | last post by:
Hi All, I need to read data from a Excel spreadsheet, but I got the problem when I tried the code below: StringBuilder sbConn = new StringBuilder(); sbConn.Append(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" ); sbConn.Append(excelFile); sbConn.Append(";Extended Properties="); sbConn.Append(Convert.ToChar(34));
0
1621
by: minhtran | last post by:
Hi Everyone Lately, I found the code as to read all file from Excel file as ".xls" from Excel before 2007, but does not work for ".xlsx" Excel 2007, Please, any help for me (new hired database Developer). A great appreciation from me. Thank you all, the code as below (this code from Internet) TextFilename = Left(TextFilename, Len(TextFilename) - 4) TextFilename += ".txt" If File.Exists(TextFilename) Then ...
0
8459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8790
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8570
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8650
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7391
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2781
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.