|
| Problem with Reading Data from Excel using ADO.NET |
 |
Thu, 27 Mar 2008 17:19:26 +000 |
Hi,
I am trying to read data from Excel and import into my ASP.NET web application.
This runs perfect on my local computer (in debug mode), but does not run when I
deploy it to the test/production environment. First, I got the Unexpected
exception, which I solved by providing access to ASPNET account on the TEMP
folders. Now I continue to get this error while trying to run the code on the
server. I 've tried with worksheets, ranges, nothing seems to work on the
server, but locally there's no problems.
The error is: The Microsoft Jet Database Engine could not find the Object
'ABC$'. Make sure the object exists and you spell its name and the path
correctly.
Anyhelp is greatly appreciated. Here's the code Thanks.
Public Overrides Sub BtnImportExcel_Click(ByVal sender As Object, ByVal args
As EventArgs)
Dim Rins_Datagrid As New DataGrid
Dim _filename As String = UploadRINFmFile.PostedFile.FileName
Dim myDataSet As New System.Data.DataSet()
Dim strConn As String =
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & _filename & ";" &
_
"Extended Properties=""Excel 8.0;"""
Dim objConn As New System.Data.OleDb.OleDbConnection(strConn)
objConn.Open()
Dim objCmdSelect As New System.Data.OleDb.OleDbCommand("SELECT
* FROM [RINS$]", objConn)
Dim myData As New System.Data.OleDb.OleDbDataAdapter
myData.SelectCommand = objCmdSelect
Dim Rin_Number As String
Dim Excel_Row_ID As Integer
Dim Excel_Rows As Integer
Dim Rin_Type As String = ""
Try
myData.Fill(myDataSet)
Rins_Datagrid.DataSource = myDataSet.Tables(0).DefaultView
Rins_Datagrid.DataBind()
Excel_Row_ID = 0
Excel_Rows = Rins_Datagrid.Items.Count
If Excel_Rows > 0 Then
For Excel_Row_ID = 0 To Excel_Rows - 1
Updated_RIN_Number =
Remove_Sp_Characters(Rins_Datagrid.Items(Excel_Row_ID).Cells(0).Text)
If Len(Updated_RIN_Number) <> 38 Then
If Updated_RIN_Number = " " Then
Exit For
Throw New Exception("Not all the Lines are of
38 digits. Error found on Line #: " & CStr(Excel_Row_ID))
End If
Next Excel_Row_ID
For Excel_Row_ID = 0 To Excel_Rows - 1
Rin_Number = ""
Rin_Number =
Remove_Sp_Characters(Rins_Datagrid.Items(Excel_Row_ID).Cells(0).Text)
If Rin_Number = " " Then Exit For
Rin_Type = Left(Rin_Number, 1)
Save_Excel_Data(parameters....)
Next Excel_Row_ID
myData.Dispose()
Else
Throw New Exception("No lines found in the Excel sheet.
Please check and try again.")
End If
Me.Page.Response.Redirect("Completed.aspx?a=" &
Me.Page.Request.QueryString("abcd"))
Catch ex As Exception
Utils.MiscUtils.RegisterJScriptAlert(Me,
"UNIQUE_SCRIPTKEY", ex.Message)
End Try
|
| Post Reply
|
|
|
|
|
|
|
|
|
|