Articles in this section
Category / Section

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

1 min read

Set a SQL data as datasource

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;
       }
   }
}

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied