Creating New Data sources and Queries
To create a new data source and query in Aspose.Cells.Report.Designer:
- Open Microsoft Excel.
- Click Build DataSet in the Aspose.Cells.Report.Designer toolbar:
All the data sources and queries are listed in the dialog box.
- A data source node:
- A data set node:
-
Select the tree’s root node.
-
Click Add.
Adding data sources and data sets
-
In the dialog box, call the data source SqlServer and the data set EmpsSalesDetail.
-
Click Next.
Adding data sets and data sources
Aspose.Cells.Report.Designer starts Microsoft Query.
-
In the Choose Data Source dialog, select New Data Source.
-
Click OK. You may also select a existing data source.
Choosing a data source
-
Input a data source name and select SQL Server from the drop-down list of database drivers.
-
Click Connect.
Creating a new data source
-
In the SQL Server Login dialog, select the appropriate value for each item. For example, set server to local, select the AdventureWorks database and select Use Trusted Connection.
-
Click OK.
Logging in to the SQL server
-
Click OK.
Note that we are now logged in to the SQL server
The new data source appears in the Choose Data Source dialog.
-
Select the new data source.
The new data source
-
Click OK to open Microsoft Query.
-
To create a query in Microsoft Query, refer to the Microsoft Query Helper. In the following sample, we create a query with parameters.
Building a query
The SQL is as follows:
SQL
SELECT C.FirstName + ' ' + C.LastName AS Employee,
DATEPART(Month, SOH.OrderDate) AS OrderMonthNum,
PS.Name AS SubCat,
SUM(SOD.LineTotal) AS Sales,
SOH.SalesOrderNumber,
P.Name AS Product,
SUM(SOD.OrderQty) AS OrderQty,
SOD.UnitPrice,
PC.Name AS ProdCat
FROM Sales.SalesOrderHeader SOH ,
Sales.SalesOrderDetail SOD ,
Sales.SalesPerson SP,
HumanResources.Employee E,
Person.Contact C,
Production.Product P,
Production.ProductSubcategory PS ,
Production.ProductCategory PC
where SOH.SalesOrderID = SOD.SalesOrderID
and SOH.SalesPersonID = SP.SalesPersonID
and SP.SalesPersonID = E.EmployeeID
and E.ContactID = C.ContactID
and SOD.ProductID = P.ProductID
and P.ProductSubcategoryID = PS.ProductSubcategoryID
and PS.ProductCategoryID = PC.ProductCategoryID
and (DATEPART(Year, SOH.OrderDate) = ?)
AND (DATEPART(Month, SOH.OrderDate) = ?)
AND (SOH.SalesPersonID =?)
GROUP BY C.FirstName + ' ' + C.LastName,
DATEPART(Month, SOH.OrderDate), SOH.SalesOrderNumber,
P.Name, PS.Name, SOD.UnitPrice, PC.Name
The query has three parameters: ReportYear, ReportMonth and EmpID.
-
From Microsoft Query’s File menu, select Return To Aspose.Cells.Report.Designer.
Returning to the report designer
The data source and query created above are listed in the dialog box.
-
Click the data source SqlServer to view its detailed information.
The new data source
-
Click the query EmpSalesDetails to view its detailed information.
Click SQL Tab to view the sql for the query
Click Columns Tab to view the columns of the query
Click Parameters Tab to view the parameters of the query