Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cannot import Excel file
Message
From
01/05/2011 20:37:32
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Cannot import Excel file
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01508964
Message ID:
01508964
Views:
91
I have used this class to import Excel files since a while. The main code is like this:
        ' Import from Excel
        Public Function ImportFromExcel() As Boolean
            Dim lcConnection As String = ""

            lcConnection = "provider=Microsoft.Jet.OLEDB.4.0; " + _
             "data source='" + cSource + "'; Extended Properties=Excel 8.0;"

            ' Assign the source directory
            oConnection = New OleDbConnection(lcConnection)

            ' Select the data from Sheet1 of the workbook
            oDataAdapter = New OleDbDataAdapter("Select * From [" + cWorkbook + "$]", oConnection)

            Try
                oDataAdapter.Fill(oDataSet)
            Catch loError As Exception
                cError = loError.Message

                ' Try to extrapolate
                Select Case cError

                    Case "External table is not in the expected format."
                        cError = aMessage(1, nLanguage)

                    Case "'Schema$' is not a valid name.  Make sure that it does not include invalid characters or punctuation and that it is not too long."
                        cError = aMessage(2, nLanguage)

                End Select

                Return False
            End Try

            ' Record count
            nCount = oDataSet.Tables(0).Rows.Count

            Return True
        End Function
One Excel file I have to import contains a weird configuration as I cannot import it. I get:

"Cannot update. Database or object is read-only."

Is this because the person who sent me the Excel has applied some kind of security or protection in the file?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform