Creating and using a Crystal Reports report in a VB.Net project using SQL Server is a multi-step process. This lesson takes you through the steps using one approach that is suitable for when the report is based on a stored procedure (SP) that generates dynamic data based on either current DB values or parameters passed to the underlying SP. There are other approaches but you will have to investigate them on your own if you are interested.
The steps are:
- Establish the SP that will supply data for the report
- Establish a VB ‘model’ for the data in the report using a VB Dataset.XSD file based on your SP results.
- Create the report and link it to the Dataset (DS) table created above.
- Design the report using the visual tools in Crystal Reports (CR).
- Create a CR report viewer on a form(s) along with whatever other interface elements you need to have (e.g., to provide SP parameter input, execute the report loading, etc.)
- Write code to execute your SP and store the result into a DataSet on the form creating the CR report viewer
- Create a report object in code and set appropriate values, including the location of the DataSet containing the report’s actual data. (Remember, the Dataset.XSD file referenced in Step 2 only contains a model of the data.)
- Write code to pass the report object to the report viewer as the report source. This causes the report to become visible in the viewer.
Sometimes it is useful to be able to change the values of text objects on a report in code. This is done in the SQL Database Documenter program (see the lesson on documenting SQL Server databases). You can change report text objects by creating a text object reference in your code and then setting properties. This must take place before the report object is passed to the report viewer control.
Note: objReport must have been declared and instantiated previously as illustrated in the “R” lines in the code listing above. Assignments such as the one below must take place before the report object (objReport) is passed to the report viewer.
Steps to do:
- Design the report using the visual tools in Crystal Reports (CR) and add Text Object, give it name eg Text1.
- Create a CR report viewer on a form(s).
- Take a looks on this code:
Dim rptTxtGroup As CrystalDecisions.CrystalReports.Engine.TextObject
rptTxtGroup = report.ReportDefinition.ReportObjects.Item(“Text1″)
rptTxtGroup.Text = “Halooo”
Yes, just this… very simple ist’n … he he he. Btw, you can use it in all object excepting OLE Object eg Picture or Blob mode.
The new My objects provide easy access to various features that developers often need but don’t necessarily know where to find in the sprawling .NET class library. Essentially, the My objects offer one-stop shopping, with access to everything from the Windows registry to the current network connection. Best of all, the My object hierarchy is organized according to use and is easy to navigate using Visual Studio IntelliSense.





