IA Crystal Report file that publishes data to a Windows or Web form

Name: sqljiommand.rpt

IA Crystal Report file that publishes data to a Windows or Web form

Name: sqljiommand.rpt

Figure 7-17

This will open the Crystal Report Gallery and allow you to select an expert to help you get started. In this example, we are going to select the Standard Report Expert, but SQL commands can be used with any of the experts listed.

The first step of the Standard Report Expert is selecting the datasource for your report; double-click the node for ODBC (RDO) and select Xtreme Sample Database 2003 as our sample datasource. This will open the dialog shown in Figure 7-18 where you can double-click Add Command to do just that.

Figure 7-18

When adding an additional datasource to an existing report using Database ^ Add/Remove Database, the option to add an SQL command is also available.

When you select Add Command, another dialog will open and allow you to enter an SQL statement to serve as the datasource for your report. Enter SELECT * from Customer in the window, as shown in Figure 7-19.

§ Add Comniiiiiii To Report @

Enter SQL query in the box below. Press the OK button when you are finished.

SELECT ' from Customer

DK Cancel

Click OK, and Crystal Reports will treat the results of this query as a virtual table. You can now use the fields you have specified in your select statement in your report.

Click Next to move on to the Fields tab, and where you would normally see a table to select data from, you will see your command. It behaves just like a table in this dialog, so click the + to expand the command, as shown in Figure 7-20 and you will see the results of your SQL command, in this case the Customer table.

Figure 7-20

Now select the fields you want to see on your report, which in this case are:

Customer Name

Contact First Name

Contact Last Name



That's all you need to do to make a basic report based on an SQL command, so click Finish to generate the report, and your Report Designer should show these fields in the Details section of sql_command.rpt. You know how to preview your report now, but here is a reminder of the basic steps:

□ Drag the CrystalReportViewer (under Windows Forms in the Toolbox) to Form1.vb

□ Drag ReportDocument (under Components in the Toolbox) to Form1.vb

□ Double-click the CrystalReportViewer that sits on your form to generate the procedure that loads your report when you run the report

□ Insert the following code in the procedure:

CrystalReportViewer1.ReportSource = New sql_command()

When you run your report, it should look something like the report in the Figure 7-21, and you now know how to create a report based on a Virtual Table created from an SQL command.

MairiReport I

SQL Command Report

Was this article helpful?

0 0

Post a comment