G
Guest
I wrote an application to pull data from certain ranges of an Excel workbook.
The application works great for the first 2 of 4 sections I created. I
created the third section of code and the code is correct; however, it isn't
pulling the data.
Below is a short / complete version of the page. I verified the problem is
not in the code. I did this by copying the original file to a new file
(copied all the cells, not the physical file). The new file ran just as
expected. I can't post the original file due to the nature of its contents,
but I can explain the file.
The (original) file had frozen panes (which I unfroze to no avail). The
file also had a few locked cells which I unlocked to no avail. I know the
range names are correct because I checked them a million times.
The code listed below will write out an exception saying 'Range01' was not
found in the file. Then it will bomb on the datagrid binding since it isn't
in a try block (it is in the real program). When I change to any other file
with 'Range01' in the file it works just fine. The cell types are the same
for all the excel files I have tested, they are of type Number.
I can procede with the new file, but I would like to know what is causing
the problems so if there are issues down the line I know what to change.
Thanks,
Ryan
'Code:
Protected Holder As System.Web.UI.WebControls.PlaceHolder
Protected eConn As OleDbConnection
Protected eData As DataSet
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
eConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=" + Server.MapPath("[EXCEL_FILE_HERE]") + _
";" + "Extended Properties=Excel 8.0;")
Dim eSQL As String = "SELECT * FROM Range01"
Dim eCmd As New System.Data.OleDb.OleDbDataAdapter(eSQL, eConn)
Try
eData = New System.Data.DataSet()
eCmd.Fill(eData)
Catch ex As Exception
Response.Write("<br><br>" + ex.ToString())
Response.Flush()
End Try
Dim dg As New DataGrid()
dg.DataSource = eData
dg.DataBind()
Holder.Controls.Add(dg)
eData.Clear() : eData.Dispose()
eConn.Dispose()
End Sub
The application works great for the first 2 of 4 sections I created. I
created the third section of code and the code is correct; however, it isn't
pulling the data.
Below is a short / complete version of the page. I verified the problem is
not in the code. I did this by copying the original file to a new file
(copied all the cells, not the physical file). The new file ran just as
expected. I can't post the original file due to the nature of its contents,
but I can explain the file.
The (original) file had frozen panes (which I unfroze to no avail). The
file also had a few locked cells which I unlocked to no avail. I know the
range names are correct because I checked them a million times.
The code listed below will write out an exception saying 'Range01' was not
found in the file. Then it will bomb on the datagrid binding since it isn't
in a try block (it is in the real program). When I change to any other file
with 'Range01' in the file it works just fine. The cell types are the same
for all the excel files I have tested, they are of type Number.
I can procede with the new file, but I would like to know what is causing
the problems so if there are issues down the line I know what to change.
Thanks,
Ryan
'Code:
Protected Holder As System.Web.UI.WebControls.PlaceHolder
Protected eConn As OleDbConnection
Protected eData As DataSet
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
eConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=" + Server.MapPath("[EXCEL_FILE_HERE]") + _
";" + "Extended Properties=Excel 8.0;")
Dim eSQL As String = "SELECT * FROM Range01"
Dim eCmd As New System.Data.OleDb.OleDbDataAdapter(eSQL, eConn)
Try
eData = New System.Data.DataSet()
eCmd.Fill(eData)
Catch ex As Exception
Response.Write("<br><br>" + ex.ToString())
Response.Flush()
End Try
Dim dg As New DataGrid()
dg.DataSource = eData
dg.DataBind()
Holder.Controls.Add(dg)
eData.Clear() : eData.Dispose()
eConn.Dispose()
End Sub