473,569 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem Reading Excel Spreadsheet From VB.NET

Hi all,

I have a little program that uses OleDb to open and read an Excel
spreadsheet from VB.NET. The problem I'm running into is it's not reading
the column headers... The Excel worksheet looks has the following columns:

Data Description / Source / 1990 / 1991 / 1992 / etc.

It's set up as a pivot-table (at least I think so... not too familiar with
Excel Pivot Tables), based on the first two columns. Anyway, when I run the
application I can open and read the first two column headings, but the
others all come through as "F3", "F4", etc. Anyone have any ideas? Here's
my code:

Dim objConn As OleDbConnection = New OleDbConnection (sConnectionStr ing)
objConn.Open()
Dim strCmd As String = String.Format(" SELECT * FROM [{0}]", table)
Dim objCmdSelect As OleDbCommand = New OleDbCommand(st rCmd, objConn)
Dim objAdapter1 As OleDbDataAdapte r = New OleDbDataAdapte r
objAdapter1.Sel ectCommand = objCmdSelect
objAdapter1.Fil l(objDataset1)
Dim Arr As New ArrayList
For Each c As DataColumn In ds.Tables(0).Ro ws(0).ItemArray
Dim s As String = c.ColumnName
Arr.Add(s)
Next
objAdapter1.Dis pose()
objCmdSelect.Di spose()
objConn.Close()
objConn.Dispose ()
TIA
Nov 21 '05 #1
4 2606
Oops. Posted to the wrong place, let me try again. Please excuse
double-post:

I changed the name of one of the columns to "X" and it read the ColumnName
correctly. I guess it's assigning alphanumeric "F3, F4, etc." because the
ColumnNames are all numeric (1990, 1991, etc.) Is there any way to force it
to recognize these values as actual ColumnNames so I don't lose the
information?

Thanks
"Michael C#" <xy*@abcdef.com > wrote in message
news:lj******** ********@fe08.l ga...
Hi all,

I have a little program that uses OleDb to open and read an Excel
spreadsheet from VB.NET. The problem I'm running into is it's not reading
the column headers... The Excel worksheet looks has the following
columns:

Data Description / Source / 1990 / 1991 / 1992 / etc.

It's set up as a pivot-table (at least I think so... not too familiar with
Excel Pivot Tables), based on the first two columns. Anyway, when I run
the application I can open and read the first two column headings, but the
others all come through as "F3", "F4", etc. Anyone have any ideas?
Here's my code:

Dim objConn As OleDbConnection = New OleDbConnection (sConnectionStr ing)
objConn.Open()
Dim strCmd As String = String.Format(" SELECT * FROM [{0}]", table)
Dim objCmdSelect As OleDbCommand = New OleDbCommand(st rCmd, objConn)
Dim objAdapter1 As OleDbDataAdapte r = New OleDbDataAdapte r
objAdapter1.Sel ectCommand = objCmdSelect
objAdapter1.Fil l(objDataset1)
Dim Arr As New ArrayList
For Each c As DataColumn In ds.Tables(0).Ro ws(0).ItemArray
Dim s As String = c.ColumnName
Arr.Add(s)
Next
objAdapter1.Dis pose()
objCmdSelect.Di spose()
objConn.Close()
objConn.Dispose ()
TIA

Nov 21 '05 #2
I think I found the solution. Setting HDR=YES in the Extended Properties of
the OleDb Connection string seems to do the trick.

Thanks

"Michael C#" <xy*@abcdef.com > wrote in message
news:RH******** *******@fe08.lg a...
Oops. Posted to the wrong place, let me try again. Please excuse
double-post:

I changed the name of one of the columns to "X" and it read the ColumnName
correctly. I guess it's assigning alphanumeric "F3, F4, etc." because the
ColumnNames are all numeric (1990, 1991, etc.) Is there any way to force
it
to recognize these values as actual ColumnNames so I don't lose the
information?

Thanks
"Michael C#" <xy*@abcdef.com > wrote in message
news:lj******** ********@fe08.l ga...
Hi all,

I have a little program that uses OleDb to open and read an Excel
spreadsheet from VB.NET. The problem I'm running into is it's not
reading the column headers... The Excel worksheet looks has the
following columns:

Data Description / Source / 1990 / 1991 / 1992 / etc.

It's set up as a pivot-table (at least I think so... not too familiar
with Excel Pivot Tables), based on the first two columns. Anyway, when I
run the application I can open and read the first two column headings,
but the others all come through as "F3", "F4", etc. Anyone have any
ideas? Here's my code:

Dim objConn As OleDbConnection = New OleDbConnection (sConnectionStr ing)
objConn.Open()
Dim strCmd As String = String.Format(" SELECT * FROM [{0}]", table)
Dim objCmdSelect As OleDbCommand = New OleDbCommand(st rCmd, objConn)
Dim objAdapter1 As OleDbDataAdapte r = New OleDbDataAdapte r
objAdapter1.Sel ectCommand = objCmdSelect
objAdapter1.Fil l(objDataset1)
Dim Arr As New ArrayList
For Each c As DataColumn In ds.Tables(0).Ro ws(0).ItemArray
Dim s As String = c.ColumnName
Arr.Add(s)
Next
objAdapter1.Dis pose()
objCmdSelect.Di spose()
objConn.Close()
objConn.Dispose ()
TIA


Nov 21 '05 #3
Also, just a shot in the dark, I'd bet that if you changed them from the
default of numeric to character they'd come up correct, too.

On Tue, 25 Jan 2005 22:32:24 -0500, Michael C# <xy*@abcdef.com > wrote:
I think I found the solution. Setting HDR=YES in the Extended
Properties of
the OleDb Connection string seems to do the trick.

Thanks

"Michael C#" <xy*@abcdef.com > wrote in message
news:RH******** *******@fe08.lg a...
Oops. Posted to the wrong place, let me try again. Please excuse
double-post:

I changed the name of one of the columns to "X" and it read the
ColumnName
correctly. I guess it's assigning alphanumeric "F3, F4, etc." because
the
ColumnNames are all numeric (1990, 1991, etc.) Is there any way to
force
it
to recognize these values as actual ColumnNames so I don't lose the
information?

Thanks
"Michael C#" <xy*@abcdef.com > wrote in message
news:lj******** ********@fe08.l ga...
Hi all,

I have a little program that uses OleDb to open and read an Excel
spreadsheet from VB.NET. The problem I'm running into is it's not
reading the column headers... The Excel worksheet looks has the
following columns:

Data Description / Source / 1990 / 1991 / 1992 / etc.

It's set up as a pivot-table (at least I think so... not too familiar
with Excel Pivot Tables), based on the first two columns. Anyway,
when I
run the application I can open and read the first two column headings,
but the others all come through as "F3", "F4", etc. Anyone have any
ideas? Here's my code:

Dim objConn As OleDbConnection = New OleDbConnection (sConnectionStr ing)
objConn.Open()
Dim strCmd As String = String.Format(" SELECT * FROM [{0}]", table)
Dim objCmdSelect As OleDbCommand = New OleDbCommand(st rCmd, objConn)
Dim objAdapter1 As OleDbDataAdapte r = New OleDbDataAdapte r
objAdapter1.Sel ectCommand = objCmdSelect
objAdapter1.Fil l(objDataset1)
Dim Arr As New ArrayList
For Each c As DataColumn In ds.Tables(0).Ro ws(0).ItemArray
Dim s As String = c.ColumnName
Arr.Add(s)
Next
objAdapter1.Dis pose()
objCmdSelect.Di spose()
objConn.Close()
objConn.Dispose ()
TIA




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Nov 21 '05 #4
Actually I tried that and it didn't work with HDR=YES. I'm assuming that
OleDb probably won't let you use all-numeric names for columns? Not sure,
but that's what it ended up looking like. I ended up setting the extended
properties to HDR=NO and treating the first line as just another row of
data. Also had to set IMEX=1 in the extended properties to get consistent
results.

Thanks,
Michael C#

"Al Jones" <al**********@s hotmail.com> wrote in message
news:opsk6623o1 xhg4go@aljones. ..
Also, just a shot in the dark, I'd bet that if you changed them from the
default of numeric to character they'd come up correct, too.

On Tue, 25 Jan 2005 22:32:24 -0500, Michael C# <xy*@abcdef.com > wrote:
I think I found the solution. Setting HDR=YES in the Extended
Properties of
the OleDb Connection string seems to do the trick.

Thanks

"Michael C#" <xy*@abcdef.com > wrote in message
news:RH******** *******@fe08.lg a...
Oops. Posted to the wrong place, let me try again. Please excuse
double-post:

I changed the name of one of the columns to "X" and it read the
ColumnName
correctly. I guess it's assigning alphanumeric "F3, F4, etc." because
the
ColumnNames are all numeric (1990, 1991, etc.) Is there any way to
force
it
to recognize these values as actual ColumnNames so I don't lose the
information?

Thanks
"Michael C#" <xy*@abcdef.com > wrote in message
news:lj******** ********@fe08.l ga...
Hi all,

I have a little program that uses OleDb to open and read an Excel
spreadsheet from VB.NET. The problem I'm running into is it's not
reading the column headers... The Excel worksheet looks has the
following columns:

Data Description / Source / 1990 / 1991 / 1992 / etc.

It's set up as a pivot-table (at least I think so... not too familiar
with Excel Pivot Tables), based on the first two columns. Anyway,
when I
run the application I can open and read the first two column headings,
but the others all come through as "F3", "F4", etc. Anyone have any
ideas? Here's my code:

Dim objConn As OleDbConnection = New OleDbConnection (sConnectionStr ing) objConn.Open()
Dim strCmd As String = String.Format(" SELECT * FROM [{0}]", table)
Dim objCmdSelect As OleDbCommand = New OleDbCommand(st rCmd, objConn)
Dim objAdapter1 As OleDbDataAdapte r = New OleDbDataAdapte r
objAdapter1.Sel ectCommand = objCmdSelect
objAdapter1.Fil l(objDataset1)
Dim Arr As New ArrayList
For Each c As DataColumn In ds.Tables(0).Ro ws(0).ItemArray
Dim s As String = c.ColumnName
Arr.Add(s)
Next
objAdapter1.Dis pose()
objCmdSelect.Di spose()
objConn.Close()
objConn.Dispose ()
TIA



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Nov 21 '05 #5

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

Similar topics

0
3115
by: Alex Shirley | last post by:
Hi I'm still banging my head on how to import an Excel XML spreadsheet into a dataset. The code will work for standard XML files, but not XML files made with Excel (I get 'Specified cast is not valid' with the xmlread statement). What do I need to do? ... transform it perhaps? How? Or is there a better way?
6
18827
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at the data in the excel file that if the first character in the excel file cell is numeric it will read and write only numeric values only. If I...
0
2928
by: ImraneA | last post by:
Hi there Have a database, where front-end interface allows user to select a ms access database. From there, standard tables are linked. Routine, that creates a spreadsheet, for each table a separate sheet within spreadsheet is created. Particular fields are selected. User requires fields to be auto-fitted. Problem, is that some tables...
3
1745
by: Eyal Zinder | last post by:
Hello All, Here is a little problem I ran into. I'd like to see if anyone can help me solve it I have an HTML table that I assign to a label control. I set my Response.ContentType = "application/vnd.ms-excel", so that I can present this html table as an Excel Document. If the amount of data (number of rows) in the table is relatively low,...
5
8930
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column headers). I used ODBC in my VB.NET program to read that spreadsheet into a dataset, to make it easy to manipulate. The code I use to read it is as the...
13
13214
by: nuti | last post by:
Hi all, I am fairly new to VB.I am trying to figure out as how to write a script so that i can read the data from an excel sheet to Access. can u guys please help me out? cheers, nuti
9
22484
by: dba123 | last post by:
I need some help and direction on what classes and an example or two (article) on how to read an Excel Worksheet and insert one column into a database table column. I am using .NET 2.0 only. What namespaces and classes should I use and how? -- dba123
3
4456
by: S_K | last post by:
Hi, I have a problem when I try to save a .CSV file from an ASP.NET web page and the client has Excel open already. The symptoms are: 1) The web page is currently displaying the Excel spreadsheet with the accurate data. 2) The .CSV file is saved from the server to the local hard drive of the client. 3) An Excel spreadsheet is already...
9
2763
by: QCLee | last post by:
Sir can you help me to transfer my Access Query to MS excel? i have a command button on the form to export the parameter query named "HVACWindwardQuery" to excel spreadsheet and i got the codes from searching on the internet and books but the problem is when i run the command button "Export" it just only open the Blank Spreadsheet, no ...
0
7703
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...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6286
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...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5222
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.