Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 686

"Multiple-step OLE DB operation generated errors" when writing text to Excel

$
0
0
Hi all,

I have an Excel sheet which is filled with data using classic ASP. All the data I enter is all numeric. Now I am trying to write text to a certain cell in Excel, but this is generating an error:
Quote:

Provider error '80040e21'

Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
When I write a numeric value to the cell I do not get this error and everything works fine. I am guessing it has something to do with the data type and/or the connection string, but cannot figure out what's wrong. I set the data type in the Excel template for this spicific cell to "text".

This is the code I am using:
Code:

' first copy the template file to a temp file
Dim fs, file
Set fs=Server.CreateObject("Scripting.FileSystemObject")
file = server.mappath("../tmp/" & fs.GetTempName)
fs.CopyFile server.mappath("../layout/dashboard.xlsx"), file

' setup connection
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Mode = adModeReadWrite
oConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="&file&";Extended Properties=""Excel 12.0;HDR=Yes;ReadOnly=False;"""

' create recordset object
        Set oRS = Server.CreateObject("ADODB.Recordset")
        oRS.ActiveConnection = oConn
        oRS.Source = "SELECT * FROM B8:BS100"
        oRS.CursorLocation = 1
        oRS.CursorType = 1
        oRS.LockType = 3
        oRS.Open

' write text to the cell
        oRS.Move 1, 1
        oRS.Fields(15).Value = "aaa"

This will generate the error as quoted before. If I would change "aaa" to, for example, "123" the error doesn't show.

Anyone has any idea how to fix this? Many thanks in advance!

Regards,
Peter Bosch

Viewing all articles
Browse latest Browse all 686

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>