Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel column headers

Status
Not open for further replies.

SQLScholar

Programmer
Aug 21, 2002
2,127
GB
Hey all,

I have a piece of VB.net code within SSIS that seems to do nearly what i want it to do. However where i am currently saying

Code:
MsgBox(Reader.Item(0))

it brings back what is on row 2. I want the row headers first, so i want whats on row1. Or the column name, field name - however you want to call it. How can i get this? Here is my current code:

Code:
            Dim excelFile As String
            Dim connectionString As String
            Dim conn As OleDbConnection
            Dim Reader As OleDbDataReader
            Dim cmd As New OleDbCommand


            Dim SheetArray As String() = DirectCast(Dts.Variables("Sheetnames").Value, System.String())

            connectionString = "Provider =Microsoft.Jet.OLEDB.4.0; Data Source =""" + Dts.Variables("Filename").Value.ToString + """; Extended Properties =""Excel 8.0;HDR=Yes;IMEX=1""; "
            conn = New OleDbConnection(connectionString)
            conn.Open()
            cmd.Connection = conn

            For Each Sheet As String In SheetArray
                cmd.CommandText = "SELECT * from [" + Sheet + "]"
                Reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
                Try
                    While (Reader.Read)
                        MsgBox(Reader.Item(0))
                    End While
                Finally
                    Reader.Close()
                End Try


            Next

            conn.Close()
            conn = Nothing

TIA

Dan

----------------------------------------

Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Dr. Seuss

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
Aha - found it. If anyone else is looking the property is GetName

----------------------------------------

Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Dr. Seuss

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top