How to refresh pivot table excel Using ClosedXML and C# - pivot-table

I am trying to refresh pivot table using C# and CLosedXml dll.
I have source data which is dynamically updated from database. I have pivot table template which gets changed based upon the data in source destination. It works perfectly when I am trying manually.
Now I need to refresh the pivot table through programming language (i.e. C#) and closedXML.
Can anyone please help me on this problem?

Pivot table rendering is not supported in ClosedXML yet. The pivot table should refresh/render when you open the file in Excel though.

Related

Importing data from Excel to SQL table using button

I have an Excel file that looks like the below
System | Status
Test OK
Test2 Down
Test3 OK
I also have a SQL server table with the same columns.
What I want is a button on the Excel sheet that once clicked, will truncate the SQL table and insert the values from the Excel table into the SQL table.
I have tried the below step but I am struggling due to my lack of understanding of developing in Excel (I am a SQL developer)
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/84725bcb-328d-4aed-8b95-d2c34dc46be4/need-to-update-sql-server-table-on-click-of-excel-button?forum=sqldataaccess
Any help would be massively appreciated!
Thanks
We have created an Excel Add-In for updating tables from Excel to SQL Server which have a Save button that will save your changes in Excel to the mapped table in SQL Server. The Add-In is built for non-technical people so it is rather straightforward to set up the spreadsheet without having to write any code.
It won't truncate the table, but there are a couple of ways to update the table which hopefully will give you the same result. Without knowing your exact use case, I would propose to either just do an update of the table from Excel if that meets your requirements, or add a timestamp column and let the Add-In write the timestamp to each updated/inserted row and then only use the last updated/inserted rows (you can also let the Add-In delete all previous rows after a new insert).
If that's of interest, you can read more here and download a free trial.
Disclaimer: I'm the founder of the company.

Generate DDL (Create) in SSIS from an Input Source

Suppose you have an Source Component and you are doing a simple One-to-One data load to a Desination Component. A Sample screenshot is as below:
Now when i open my Destination component, i find that it asks me to enter the name of the table where the data would be loaded.
In the dropdown, i find that the names of the table are getting populated which are already present in my database.
My queries are as below:
Do i need to manually create the tables in the database first and then only i can execute the data flow?
Is there any way, i could get the all the Source columns and generate a DDL statement to create the table, if required. I am NOT asking for dynamically creating a table. Just a possible solution to get all you input columns and data-types lists and then auto-generate a sample DDL or SQL query.? (Imagine a scenario where in you have 200-500 columns in a text file/flat file,, manually creating a table with all the columns gets tough)
N.B: Integration Tools like Pentaho Kettle provides you with a similar feature. You don't have to worry about table creation. If its not present, you can use kettle feature to create one in the database.
It would be really helpful if anyone can help me in this. I am also a newbie to SSIS. Not much of a knowledge. Thanks :)

What would be the best method for building Dynamic Reports from my SQL DB Data?

I am building a simple database with about 6-7 tables. I will be setting a schedule to do a clean import from a .txt file.
I want to take this data and create a report, like I would do in an excel spreadsheet, convert it to a pdf and post it to our company intranet for those interested to access it.
I'm trying to think of the best way to build my report. Would I just use an excel spreadsheet with a direct connection to the database? Would I create some sort of console application (c/c#/vb/vb.net) that would query the db, generate the report in an excel file, convert to pdf and save?
I'm quite comfortable in these different languages, just not as experienced in the reporting services (although I do have a lot of experience working with EXCEL and VBA Macros) but I want to get into it (SSRS) and get familiar with it as I will be doing a lot of projects like this in the future. This is seems like an easy one to get my hands dirty with and learn and build off of.
Any insight or suggestions would be greatly appreciated.
Thanks so much!
My suggestion:
Create desired SQL queries to retrieve the data in desired form
Link these queries to your Excel sheet, perhaps directly in form of pivot tables for aggregation of results
Using VBA, you can easily create PDF from the data at the click of a button
The initial design will be time intensive, but after that, everything is automated and one just needs to press the button that creates the PDF.
How to link Access queries to your Excel file:
Data --> Get external Data
You can easily refresh all data whenever you open the Excelsheet by using the code below in the On Open event of the workbook:
ThisWorkbook.RefreshAll
If you need further clarification, do not hesitate to ask
If your end goal is to create a PDF that will be out on your intranet then I would create the report in SSRS. Then you can schedule it to run and output a PDF to your network location.
I've had good experiences using a pivot table in Excel which is a connected table to your SQL database.
In the connection parameters in Excel there is a field where you can define your SQL query, whether it be to call a stored procedure or just a simple SELECT statement.
The main reason I prefer a pivot table SQL connection rather than a normal table connection is because if you have a chart that references the connected table, the chart formatting will be reset when you refresh your connection (if you need to updated your report).
If I use a chart that references a pivot table (or a pivot chart) then the formatting is retained.

Dynamic Data website only displays rows that it inserted to DB

I'm pretty new to creating dynamic data websites - I created one a year ago that is working fine but now I'm trying a 2nd one and having a strange problem.
I'm using VS2010, VB.net & followed MS's waltkthrough for creating a web site using Linq to SQL. Things seem to be working with one MAJOR exception. I've pointed it to a SQL server in my domain but it won't display rows from the DB that were not created through the website. Records that I manually enter through SSMS do not show in the DD List for the table, but rows I inserted thru the website do appear.
I have cleared the table and refreshed the list view and all rows disappear. Then if I add rows via SSMS they do NOT show up but website added ones do. This is important because I'm going to be importing data from an old (non SQL) DB that I'm converting.
I really don't know where to look to resolve this - Does anyone have any ideas?
Thanks!
The records I entered thru ssms had bad values for a foreign key and evidently DD is doing inner joins instead of left outer. I don't know if that is a bug or a feature.

Visual Studio DataSet Designer Refresh Tables

In visual studio datasource designer is there any way to refresh a table and its relations/foreign key constraints while keeping the custom queries?
The way I am doing it at the moment is removing the table and adding it again. This adds all the relations and refreshes all fields.
Also if I change a fields data type, is there a way to automatically refresh all the fields in the datasource? Again without deleting the table and adding it again.
Reason for this is because some of my TableAdapters have quite a number of complex queries attached to them and when I remove the table the adapter gets removed as well including all its queries.
I am using Visual Studio 2008 and connecting to a MySQL database.
Any1 have an idea?
Each table has a default query (The one on top with the check on it). When you dragged your tables in to the dataset to create the query, it wrote a SQL statement which it uses to schema your table. Keep that query simple, you might not actually use it in code, and you can always edit that query to update the table schema.
Every time you open the default query it connects to your datasource and allows you to select new columns that weren't in there before. If you want to update your existing columns, delete all the columns out of the table before you attempt to open the query. When you save the query, your updated columns get added back.
Make sure your connection string has permissions to view column information.
I reported this to MSFT but no response. The designer hangs all the time on the simplest of SQL statements. What I found that works for me is.
Add a new table to the designer.
Save it.
Shut down visual studio 2010.
Start VS 2010.
Add one or two more SQL statements and follow steps 2-4 again.
This is a pain in the neck but the only thing that stops Visual Studio dataset designer from hanging. I experienced in this same issue in VS 2008. I am connecting to Oracle but still shutting down VS and starting it back up works, but really, this is nonsense.
You can add/change/remove fields and relation ships, but i would suggest looking into NHibernate.
You should be able to right-click the dataset in solution explorer and select "Run Custom Tool" to refresh the table and it's query/relationships.
If that command is not there, check that the dataset properties has "MSDataSetGenerator" in the Custom Tool field.
Right click on your DataSet name and select Dataset Properties
Below the Query box you will see a button for Refresh Fields.
Click on Query Designer and the new field should show in your table list.

Resources