How to modify the Data source connection of a Pivot Table by C#

Category: visual studio visualiaztion


Biju Nambiar on Fri, 02 Dec 2016 06:41:40

Hi ,

I'm new to VSTO programming,I have a pivot table which is taking data from SQL Server.I just want to change the data source of this pivot table programatically.

string con = @"OLEDB;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=PivoteNew;Data Source=BIJUC\SQL2012DEV";


wrkcon = newWorkbook.Connections.Add2("PivoteNew", " ", con, "Student");

pvttable = Globals.ThisAddIn.Application.ActiveSheet.PivotTables("PivotTable2");




This is my code,but throwing an error.

Appreciated your valuable comments.