Hi,
I'm running into a problem with relatively long fields (this one is
1351 chars long) where it's failing on the copyFromRecordset(rs) call.
The exception I'm getting is:
An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Unspecified error
Which of course is less than helpful :)
The RS is properly formatted and this is an ADODB recordset, the field
is adVarWChar, length 1600. It only seems to fail on long long data
transfers - the preceeding rows in the recordset transferred without
issue. Code snippet is below.
Anybody who can help would greatly be appreciated. I apologize for
cross posting in advance - I made a mistake in posting to vba.excel
first.
Cheers
Dave
---------------------------------------------------8<--------------------------------
Public Sub showRSinExcel(ByRef theRSList As Hashtable, Optional
ByVal actionType As excelActionType = excelActionType.actionOpen,
Optional ByVal fileName As String = Nothing)
Dim msExcel As New Excel.Application
Dim columnCount As Integer
msExcel.DisplayAlerts = False
Dim rsCount As Integer = 0
Dim theWorkbook As Excel.Workbook = msExcel.Workbooks.Add
For Each key As String In theRSList.Keys
Dim rs As ADODB.Recordset = theRSList(key)
Dim theWorksheet As Excel.Worksheet =
theWorkbook.Worksheets.Add
theWorksheet.Name = key
For j As Integer = 1 To rs.Fields.Count
theWorksheet.Cells(1, j).Interior.ColorIndex = 15
theWorksheet.Cells(1, j) = rs.Fields(j - 1).Name
columnCount = j - 1
Next
theWorksheet.Range("A2").CopyFromRecordset(rs) '<--- fails
here
theWorksheet.Columns("A:BZ").AutoFit()
rsCount += 1
Next
For i As Integer = theWorkbook.Worksheets.Count To rsCount + 1
Step -1
theWorkbook.Worksheets(i).Delete()
Next
Select Case actionType
Case excelActionType.actionOpen
msExcel.DisplayAlerts = True
msExcel.Visible = True
theWorkbook.Worksheets.Item(1).activate()
Case excelActionType.actionSave
If Not IsNothing(fileName) Then
theWorkbook.SaveAs(fileName)
msExcel.Quit()
Exit Sub
'theWorkbook.Close(False, Nothing, Nothing)
End If
End Select
msExcel.DisplayAlerts = True
msExcel.Visible = True
End Sub
------------------------------------------------------>8----------------------------------------
Dmytro Lapshyn [MVP] - 10 Apr 2006 15:53 GMT
Hi,
Which version of Excel do you use? MS support KB indicates a number of
similar problems with Excel 97, but that's quite an old version one hardly
uses nowadays...
> Hi,
>
[quoted text clipped - 70 lines]
> End Sub
> ------------------------------------------------------>8----------------------------------------
fartlegs@gmail.com - 10 Apr 2006 17:30 GMT
Using Excel 2003 (11.5612.6360)...
it's strange that it only throws these errors on large data. The way I
see it, there's probably a switch on the worksheet that you have to
call in order to bring large data in? Hm. I dunno.
Dmytro Lapshyn [MVP] - 10 Apr 2006 15:55 GMT
You can also write a similar code in VBA and see whether Excel fails as
well. If so, it might just give you a more descriptive error message (.NET
COM interop has a nasty glitch that sometimes prevents the descriptive error
info to be passed to the .NET caller even if the COM server has provided
it).