M
Michael C#
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(sConnectionString)
objConn.Open()
Dim strCmd As String = String.Format("SELECT * FROM [{0}]", table)
Dim objCmdSelect As OleDbCommand = New OleDbCommand(strCmd, objConn)
Dim objAdapter1 As OleDbDataAdapter = New OleDbDataAdapter
objAdapter1.SelectCommand = objCmdSelect
objAdapter1.Fill(objDataset1)
Dim Arr As New ArrayList
For Each c As DataColumn In ds.Tables(0).Rows(0).ItemArray
Dim s As String = c.ColumnName
Arr.Add(s)
Next
objAdapter1.Dispose()
objCmdSelect.Dispose()
objConn.Close()
objConn.Dispose()
TIA
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(sConnectionString)
objConn.Open()
Dim strCmd As String = String.Format("SELECT * FROM [{0}]", table)
Dim objCmdSelect As OleDbCommand = New OleDbCommand(strCmd, objConn)
Dim objAdapter1 As OleDbDataAdapter = New OleDbDataAdapter
objAdapter1.SelectCommand = objCmdSelect
objAdapter1.Fill(objDataset1)
Dim Arr As New ArrayList
For Each c As DataColumn In ds.Tables(0).Rows(0).ItemArray
Dim s As String = c.ColumnName
Arr.Add(s)
Next
objAdapter1.Dispose()
objCmdSelect.Dispose()
objConn.Close()
objConn.Dispose()
TIA