We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set a SQL data as a DataSource for the PivotGrid

Platform: WPF |
Control: PivotGridControl |
Published Date: November 24, 2014 |
Last Revised Date: November 24, 2014
Tags: general, wpf

How to set a SQL data as a DataSource for the PivotGrid?

 

 It can be achieved by making proper SQL based connection with the corresponding data set. The code snippet explains the same.

C#

class OrderDetails

    {

        public static DataSet GetOrderDetials()

        {

            try

            {

                DataSet ds = new DataSet();

                using (SqlCeConnection con = new SqlCeConnection(@"DataSource=Data\Northwind.sdf"))

                {

                    con.Open();

                    SqlCeCommand cmd = new SqlCeCommand(@"SELECT Top(100) [Order ID], [Product ID], [Unit Price], Quantity

                                                          FROM [Order Details] ", con);

                    SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);

                    da.Fill(ds);

                    return ds;

                }

            }

            catch(Exception e)

            {

                MessageBox.Show("Exception in connection: \t"+e.Message);

                return null;

            }

        }

    }

 

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
meir rotfleisch
Sep 13, 2015
Where do you do the actual binding of the DataSet to the PivotGrid? Reply
Vigneshwaran B [Syncfusion]
Sep 14, 2015
Hi Meir, We could bind the DataSet to the PivotGrid by setting it as an Itemsource for the grid. Please refer to the below code snippet and simple sample to illustrate the behavior. public MainWindow() { InitializeComponent(); //Binding DataView to the ItemSource this.pivotGrid1.ItemSource = OrderDetails.GetOrderDetials(); this.pivotGrid1.PivotColumns.Add(new PivotItem { FieldHeader = "OrderID", FieldMappingName = "Order ID", TotalHeader = "Total" }); this.pivotGrid1.PivotRows.Add(new PivotItem { FieldHeader = "ProductID", FieldMappingName = "Product ID", TotalHeader = "Total" }); this.pivotGrid1.PivotCalculations.Add(new PivotComputationInfo { CalculationName = "UnitPrice", FieldName = "Unit Price", Format = "C", SummaryType = SummaryType.DecimalTotalSum }); this.pivotGrid1.PivotCalculations.Add(new PivotComputationInfo { CalculationName = "Quantity", FieldName = "Quantity", SummaryType = SummaryType.Count }); } Sample Link: http://www.syncfusion.com/downloads/support/forum/119969/DataTable_Demo-1155036870.zip Thanks, Vigneshwaran B Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon