Hi there,
I am trying to create an upload functionality for my application.
User can only upload an excel format file.
I already have a standard formatted excel (which means i don't have to worry about the column fields,file extension, excel version etc..). User just have to fill the cells.
Well, it's not really uploading the excel file because what i wanted to do is just parse the excel sheet, get its data and insert it in the sql server database.
The reason for this is that I only need the data from the excel file and not the excel file itself.
I am able to do this when run in my local computer but once online, I get an error of
"The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another user, or you need permission to view its data."
I have properly set up the permissions and 100% sure that the file is not open anywhere.
Also tried putting the excel file in the server and read from there but found no luck at all.
Now, my question is, Is my approach really possible ( to parse the excel from the remote computer and get its data) then insert in the database?
Here's how I do it:
filePath = IO.Path.GetFullPath(FileUpload1.PostedFile.FileName)
try
'start parsing
Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= """ + filePath + """;Extended Properties=Excel 8.0;"
Dim rawTable As DataTable = New DataTable("ExcelTable")
' Parse the excel file.
sheetname = "Sheet1"
Using adapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("SELECT * FROM[" + sheetname + "$]", connStr)
adapter.Fill(rawTable) ' Fill to get the column headers.
End Using
Using scope As TransactionScope = New TransactionScope()
'Dim _err As Integer = 0
For i As Integer = 0 To rawTable.Rows.Count - 1
obj.Insert(rawTable(i)("Title").ToString, rawTable(i)("URL").ToString)
Next
If Err.Number <> 0 Then
Transaction.Current.Rollback()
Else
scope.Complete()
End If
End Using
Catch ex As Exception
End Try
What am i missing?
Thanks in advance for any help.
-rikuna