private void Sample()
{
// call this from a form ....
SqlConnection conn;
SqlCommand com;
DataGrid dg = new DataGrid();
dg.Parent = this;
dg.Dock = DockStyle.Fill;
String SQL =
"select o.customerID, c.CompanyName, p.productName, sum(od.quantity) as Qty " +
" from orders o " +
" inner join [order details] od on o.orderID = od.orderID " +
" inner join Products p on od.ProductID = p.ProductID " +
" inner join Customers c on o.CustomerID = c.CustomerID " +
" group by o.customerID, c.CompanyName, p.ProductName " +
" order by o.customerID";
conn = new SqlConnection( "Server=(local);Database=Northwind;uid=xx;pwd=xx");
conn.Open();
com = new SqlCommand(SQL, conn);
try
{
dg.DataSource = Pivot(com.ExecuteReader(),"CustomerID","ProductName","Qty");
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}