LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Reading data from Excel Worksheet in vb

below is the code I am using to read the column names from an excel
worksheet... its working fine except in two instances:
1) if i read from an empty worksheet then it returns F1 - how can i make it
not return anything
2) if i have multiple columns with different "types" of names then it
returns the generic (F1,F2,F3....) for example if i have 4 colums names:
"First Name", "Last Name", "1/1/2009", "City"
if these are the four coumn names(first row of the worksheet), then it
returns: "First Name", "Last Name", "F3", "City"
notice the F3 instead of the 1/1/2009 - how can i avoid this?

The user selects the excel worksheet to read from hence I dont know how many
columns are there and what kind of datatype is the column name...


Dim sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
dataSource & ";Extended Properties=""Excel 8.0;HDR=YES;IMEX=1"""
Dim dt As New DataTable
Dim da As New OleDb.OleDbDataAdapter
Dim conn As New OleDb.OleDbConnection(sConnectionString)
Dim columnList As New List(Of String)

da = New OleDb.OleDbDataAdapter("Select top 1 * from [" & worksheetName &
"]", conn)
da.Fill(dt)

For Each dc As DataColumn In dt.Columns
columnList.Add(dc.ColumnName)
Next
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading Data from an Excel Sheet Andrew Kirkby Excel Programming 1 September 23rd 08 09:55 PM
Reading data arrays from multiple data files in excel Hankjam[_2_] Excel Discussion (Misc queries) 0 February 7th 08 08:29 PM
Reading data from PPT and purge data to Excel and image [email protected] Excel Programming 1 January 17th 08 06:04 AM
Reading data from excel P.Nishanthan Excel Programming 0 May 3rd 07 09:20 AM
Reading excel data into another aplication Sean Bartleet Excel Programming 2 October 19th 05 02:15 PM


All times are GMT +1. The time now is 10:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"