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.
Unfortunately, activation email could not send to your email. Please try again.

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

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;

            }

        }

    }

 

Article ID: Published Date: Last Revised Date: Platform: Control:
2896 11/24/2014 11/24/2014 WPF PivotGridControl
Tags:
Did you find this information helpful?
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
Add Comment
You must log in to leave a comment

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.