index > Visual Studio Tools for Office > Create Pivot Table in VSTO2

Create Pivot Table in VSTO2

I'm trying to create a new Pivot table in a workbook with VSTO2.

The second line crash:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Server stack trace:
Exception rethrown at [0]:

at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Office.Interop.Excel.PivotCaches.Add(XlPivotTableSourceType SourceType, Object SourceData)
at ExcelTestPivot.ThisWorkbook.ThisWorkbook_Startup(Object sender, EventArgs e) in C:\Documents and Settings\****\ThisWorkbook.vb:line 11

Can you hel me? Thnks.

Here the code:

Dim oPiv As Excel.PivotCache

oPiv = Me.PivotCaches.Add(Excel.XlPivotTableSourceType.xlDatabase)

With oPiv

.Connection = "Data Source=.\SQLEXPRESS;Initial Catalog=exlCantieri;Integrated Security=True"

.CommandType = Excel.XlCmdType.xlCmdSql

.CommandText = "SELECT *** FROM ***"

.CreatePivotTable(TableDestination:="", TableName:="Tabella_pivot1", _

DefaultVersion:=Excel.XlPivotTableVersionList.xlPivotTableVersion10)

End With

Globals.ThisWorkbook.PivotTableWizard(TableDestination:=Globals.Foglio1.Cells(3, 1))

Globals.Foglio1.Cells(3, 1).Select()

With Globals.Foglio1.PivotTables("Tabella_pivot1").PivotFields("field1")

.Orientation = Excel.XlPivotFieldOrientation.xlRowField

.Position = 1

End With

With Globals.Foglio1.PivotTables("Tabella_pivot1").PivotFields("field2")

.Orientation = Excel.XlPivotFieldOrientation.xlColumnField

.Position = 1

End With

Globals.Foglio1.Range("B4").Select()

Globals.Foglio1.PivotTables("Tabella_pivot1").PivotCache.Refresh()




paolo
Babba72

According to Excel OM documentation, you must specify the SourceData argument if the SourceType is not xlExternal.

This seems to be the cause of the exception.




This posting is provided "AS IS" with no warranties, and confers no rights.
Mohit Gupta - MSFT

ok all it's ok.

I use ODBC connection with this string to connect to sqlexpress:

"ODBC;Description=SqlExpressLocal;DRIVER=SQL Native Client;SERVER=.\SQLEXPRESS;UID=MyUres;Trusted_Connection=Yes;APP=Microsoft Data Access Components;WSID=****;DATABASE=****;"

I'd like to know if i can use other type of connection.

Paolo72
reply 3

You can use google to search for other answers

 

More Articles

• Can't deploy VSTO 2005 Project
• How to update SQL 2005 database on a VBNET Excel 2003 Project
• How to use VSTO to replace word automation letter generation
• Trying to convert a Word document to Web
• HELP!!!!!
• Event of PowerPoint.Application confict with Process.GetProcesses...
• Drag and Drop in EXCEL
• DocumentChange event is fired when dialogs pop up
• Is it possible to link project # 1 to project # 2?
• VSTO doesn't work in a custom ActiveDocument host
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Null values displayed as 0 in OWC Pivot
• VSTO Outlook 2007 Architecture Problems
• Getting contact information from Outlook
• Help please. I need to protect my work i
• Interop.Word.dll
• Stablish cursor position in Word
• No such interface supported with v3
• Globalization and Localization Problem w
• Connecting and working with Access 2003
• Fire event when mail is arrives in sentm
• How to update Excel CommandBar via Event
• ExcelSheet Deletion
• VSTO and SolutionCodeGroupName [Was: In
• Outlook: Make mail properties readonly
• Word sub-menus not visible in VSTO 2005

Hot Articles

• VSTO Excel Deployment; Need Help; Please
• Shutdown word application forcefully
• Drag outlook contacts into my app
• Outlook addin AutoUpdate
• How to display task pane ion Word 2007?
• VSTO and AVG...HEEELP!
• Action Pane
• Using NativeWindow seems to crash Word
• Implement Intellisense in MS Word
• Add-In Only loads when debugging
• Upgrade a Combobox with queries list in
• Outlook / SQL Server 2005 Sync
• Assembly Reference Error
• edit -> delete on excel disabled, aft
• Addin - TaskPane communication

Recommend Articles

• How to include an MSI to be installed as
• create a new worksheet in a excel file u
• Get the current / active worksheet
• taskpane
• Word Document Protection
• Can I use v3 for Office 2003 and 12? Ca
• VSTO,Actions pane?? navigation buttons.
• Event of PowerPoint.Application confict
• Optional Parameters and overloading in a
• Infopath listbox question
• document_startup problems?
• Urgent Deployment problem
• writing into the document (VSTO - C#)
• Word Template Info Stored in Access??
• Convert from RTF to HTML