How to set a SQL data as a DataSource for the WPF PivotGrid?
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;
}
}
}