9CBS - Expert Outpatient Close Window Main Taste: Experience and Data on Crystal Reports, Welcome colleagues who have used crystal reports to sum up, experience, experience in the process of use! ! Author: FOXTOO (Alibaba and forty stolen) Credit value: 100 Forum: .NET technology ASP.NET problem points: 0 Reposted: 64 Posted: 2003-6-10 23:04:39 Information:
Crystal reports in ASP.NET (on)
Www.dotnet8.com 2002-9-6 dotnet
[Html] In our crystal report in VS.NET, the wake-up core is fear, the hips, the hips, the embarrassment, the gantry, the jeans, Yue, Hulu, EB, is very curiosity. After a week, after reading a large number of "Howto" documents, we successfully added some simple report to our ASP.NET program and got some small decisions.
This article teaches you how to use crystal reports in .NET web applications, you can also let you take less detours during your study. In order to get the best results, readers should best have some basic ASP.NET access to database knowledge and experience using VS.NET.
Introduction
Crystal reports can be obtained from a number of methods, one is to create using VS.NET, which provides a very rich model to operate attributes and methods at runtime. If you are using VS.NET development .NET program, you don't need to install other software, because he is already in vs.net.
advantage:
The vs.net crystal statement has some of the main advantages:
Quick report development
Ability to export complex interactive charts
Can be used in WebForm with other controls
It is possible to dynamically export the report into .pdf, .doc, XLS, HTML, RTF, etc.
structure:
Some components form a two-layer structure of the crystal report, and the web applications needed:
Client:
The client only requires an auditor that can access the embedded ASPX page report.
Server:
- Crystal Report Engine (Crengune.dll))
Through it can complete some tasks, such as merging data in the report file, the conversion report is other formats. It is also because of the role of the report engine, the Crystal Report in ASP.NET can be converted into ordinary HTML format.
- Crystal Report Designer (CRDESigner.dll))
The crystal report is created in the designer, in the designer you can design the title, insert data, formula, chart, sub-report, etc.
--.Rpt report file
The first step in the implementation report is to create this report at the Crystal Report Designer interface, and Microsoft has provided some ready-made .rpt examples in the default installation.
- Data Source
The way the .rpt file acquisition database depends on your method's choice, you can choose to make the crystal report you choose to select the data yourself without any code or you can also select manually assembled DataSet, and then transfer it to the report file.
- Crystal Report View Control (Crystal Report Viewer Web Form Control (CRWEBFORMVIEWER.DLL))
Crystal Report View control is a WebForm control that can be regarded as a container that stores reports in the .aspx page. Note: In some complex operations, the report server and the web server may not be on the same physical host, the web server transmits the HTTP request to the report server. Crystal reports can also be performed when WebService is performed. Execution mode
Crystal report data can be implemented using the following method:
- PULL mode:
When the request is requested, the crystal report directly connects the database directly to the database and assembles this data.
- Push mode:
At this time, the development table has to write code connection data and assemble the DataSet, and transfer it to the report. In this case, by using connection sharing and limiting the size of the record set, the report performance can be maximized.
Report type:
Crystal Report Designers can directly contain reports to engineering and can use separate report objects.
- Strongly-Typed report:
When you add the report file to the project, it turns into a "strongly-type" report. In these cases, you will have the power to create the object of the report, which will reduce some code and provide some performance.
- UN-TYPED report:
The report here is not directly included in the project, so it is called the 'UN-TYPED' report. In this case, you have to establish an instance using the "ReportDocuemt" object of the crystal statement, and "manual" manual apipe.
Other considerations
- Although the Crystal Report Viewer has some cool features, such as zoom, page navigation, etc. But he does not provide print function, you have to call the printed function of the visitors.
- Crystal report in vs.net If no registration, then it can only use 30 times, 30 times, "save" can not be used again. To avoid this, you are not in http://www.crystaldecisions.com/ here. (It seems that it is not a case, it seems that it can be used for a long time, but it is not supported)
- The default installed crystal report can only support 5 users, in order to support more users, you have to purchase licenses in http://www.crystaldecisions.com/.
Let us feel it ---- use a ready-made crystal report file in ASP.NET
1) Drag the Crystal Report Viewer from the WebForm toolbar to the .aspx page.
2) Match the properties window of the Crystal Report Viewer Control
3) Click the [...] button to view the "Data Binding" property and pop up the DataBinding window.
4) Select "Report Source" from the "Bindable property" area of the left.
5) Select the "Custom Binding Expression" radio button, specify the file name and path of the.rpt file in the window on the bottom of the right, for example: "C: // Program Files // Microsoft Visual Studio.Net//crystal Reports // Samples // Reports // General Business // World Sales Report.rpt ", then" OK "
Note: The file "World Sales Report.rpt" file is created during VS.NET installation. If you specify another directory during the installation process, you'd better confirm the correctness of the path.
The above steps is actually inserted into the following code to the ASP.NET file:
as well as:
ID = "CrystalReportViewer1"
Runat = "server" width = "350px" Height = "50px" reportource = '">
Note: The style generated by ReportSource in the code in the code in my vs.net official version of the flying knife is not like this, it is:
Reportsource = "" "
This is wrong, there will be an error message, there are two errors:
You must manually modify it in accordance with the format described in this article, which is also a BUG of VS.NET.
6) Call the DataBind method in the Page_Load method. (Code is VB.NET)
Private sub page_load (byval sender as system.object, byval e as system.EventArgs)
DataBind ()
End Sub
7) Save and compile your page. Now, you have a WebForm page for embedded crystal reports.
Note: In the actual development, an error that cannot be accessed in the INETSRV directory will appear at the beginning, and the solution is to change the security properties of its directory, so that the user user has writable permissions. Flying knife I found that the solution from the .NET system has been useless, or it may be the reason I use the Windows.NET operating system.
[/ Html]
Reply to: foxtoo (Alibaba and forty stolen) () reputation: 100 2003-6-10 23:04:53 Score: 0 ASP.NET Water Report (middle)
Www.dotnet8.com 2002-9-6 dotnet
[Html] use PULL mode
We will pass the following steps to perform crystal reports through the PULL mode.
1. First create the RPT file and set some must-have data connections using the Crystal Report Design Interface.
2. Drag and drop a CrystalReportViewer control to the ASPX page, set its properties to specify the.rpt file we created in the previous step.
3. Call the DataBind method in the code.
Create a .rpt file:
1) On right-click "Solution Over", select "Add" - Add New Items in the pop-up menu -> "Crystal Report" -> "Crystal Report"
2) Select "As the Blank Report" radio button in the Crystal Report Library, and finally click OK.
3) The crystal report designer will pop up here.
4) Right-click Details Zone, select "Database" -> "Add / Delete Database ..."
5) In the "Database Expert" pop-up, the OLE DB (ADO "option is expanded, and another" OLE DB (ADO) window will pop up.
6) In the OLE DB (ADO "pop-up window, select" Microsoft Ole DB Provider for SQL Server "and" Next "
7) Specify the information of the connection
Server: Aspcn (What is your machine written?
User ID: SA
password:
Database: PUBS
8) Click "Next" and finally click the "Finish" button.
9) At this point you can see the database we have selected in the Database Expert window.
10) Extend the "PUBS" database, extend the "table", select the "Stores" table and add it to the "Selected Table" area, click the "OK" button.
11) Now displaying the table you selected in the "Database Field" area in the Field Source Browser, as well as the fields in the table.
12) Drag and drop the desired field to enter the "Detail" area of the report. The field name will automatically appear in the "Header" area. If you want to modify the header, you can right-click the text in the Header area, select the Edit Text Object option and edit. 13) Save so that we have a crystal report file.
Create a CrystalReportViewer control
14) Go back to WebForm, drag and drop a Crystal Report Viewer control to the page.
15) Tune the properties window of the Crystal Report Viewer control, select the "DataBindings" area Click [...]
16) In "Crystal Report Viewer Data Binding Window", select "ReportSource" in the "Bonitable Properties" on the right, and select the "Custom Binding Expression" in the lower right corner to specify the .rpt file path.
17) At this point you can see the preview of report files that use some virtual data in the Crystal Report Viewer control.
Note: In the above example, CrystalReportViewer can call real data directly when design, because the data has been saved. In this case, when the data is not saved, he cannot display data when it is not saved. Instead, this is to show some virtual data, and only real data is selected only when executed.
Code Behind program design
18) Call the DataBind method in the Page_Load method.
Execute your program
19) Create and run your program!
You can now use some of the features built into the WEB page, such as page navigation, zoom, and so on.
[/ Html]
Crystal report in ASP.NET (below)
Www.dotnet8.com 2002-9-6 dotnet
[HTML] We use the following steps to perform crystal reports using the Push mode:
Design a DataSet
2. Create a .rpt file simultaneously assign it to the DataSet established in the previous step.
3. Drag and drop a CrystalReportViewer control in the ASPX page to connect to the previous RPT file.
4. Access the database in your code and save the data into DataSet
5. Call the DataBind method.
Design a DataSet
1) Right-click "Solution Browser", select "Add" - "Add New Item" -> "Data Set"
2) Drag and drop the "Stores" table in "SQL Server" in Server Explorer ".
3) There will be a structural diagram of a Stores table in the data set.
--. only contains a structural diagram in .xsd file, there will be no data in it.
Create a .rpt file:
4) Creating this file using the methods described above, the only difference is to use the data set to replace the front direct connection data.
5) After establishing the .rpt file, right click on "Details" -> Add / Remove Database.
6) In the Database Expert window, expand "Project Data" (instead of previous OLEDB), expand "ADO.NET Dataset" - "Dataset1", select "Stores" table.
7) Add "Stores" table to "Selected Table", click "OK"
8) Create a WebForm using the method in PULL mode
Create a Crystal Report Viewer control
9) Establish a Crystal Report Viewer control and set its properties, which is consistent with the PULL mode.
Code Behind code:
10) Use the subunies below in the Page_Load method:
VB.NET code:
Sub bindreport ()
Dim myconnection as new sqlclient.sqlconnection () MyConnection.connectionstring = "server = (local) / netsdk; data = pubs; trusted_connection = yes"
Dim MyCommand as new sqlclient.sqlcommand ()
Mycommand.connection = myconnection
Mycommand.commandtext = "SELECT * from Store"
Mycommand.commandtype = commandtype.text
Dim myda as new sqlclient.sqldataadapter ()
Myda.selectcommand = myCommand
DIM MYDS AS New DataSet1 ()
'This is the DataSet we used in design patterns.
Myda.Fill (MyDS, "Stores")
'You have to use the same name as you in front of DataSet.
Dim ORPT AS New CrystalReport1 ()
'Crystal report binding
ORPT.SetDataSource (MYDS)
'Setting a crystal report ReportSource
CrystalReportViewer1.Reportsource = ORPT
End Sub
C # code:
Private void bindreport ()
{
String strProvider = "server = (local); database = pubs; uid = sa; pwd =";
CrystalReport1 Ocr = New CrystalReport1 ();
DataSet1 DS = New DataSet1 ();
SqlConnection myconn = new SqlConnection (STRPROVIDER);
Myconn.open ();
String strasel = "select * from stores";
SqldataAdapter myadapter = new sqldataadapter (strsel, myconn);
Myadapter.Fill (DS, "Stores");
Ocr.SetDataSource (DS);
This.CrystalReportViewer1.Reportsource = OCR;
}
Note: In the code above, you have to pay attention to the ORPT is a report file of "strongly typed". If you need to use the "untyped" report, you have to use the ReportDocument object, and then call the report file.
Run your program.
11) Run your program
Export report files into other formats
You can export report files into the following format:
PDF (Portable Document Format)
1. 2. DOC (MS Word Document)
2. 3. XLS (MS Excel Spreadsheet)
3. 4. HTML (Hyper Text Markup Language - 3.2 Or 4.0 Compliant)
4. 5. RTF (Rich Text Format) Export Reports with PULL Mode
When the file using the PULL mode is exported, the crystal report accurately opens the required data, the following is the code to perform the export function:
C # code:
VB.NET code:
Private sub button1_click (byvale as system.object, byval e as system.eventargs) Handles Button1.click
Dim myreport as crystalreport1 = new crystalReport1 ()
'Note: Here we build a Strong-type crystal report instance.
DIM DISKOPTS as crystaldecisions.shared.diskfileDestinationOptions = new crystaldecisions.shared.diskFileDESTINATIONOPTIONOS ()
MyReport.ExportOptions.exportDestinationType = crystaldecisions. [Shared] .exportDestinationType.Diskfile
'The option is also required when exporting into other files.
'Such as Microsoft Exchange, MAPI, etc.
MyReport.exportOptions.exportFormattype = crystaldecisions. [shared] .exportformattype.portabledocformat
'Here we export becomes .pdf format file, you can also choose other types of files above.
Diskopts.diskFileName = "c: /output.pdf"
'If you don't specify an exact directory, the file will be saved to the [Windows] / system32 directory.
MyReport.exportOptions.DestinationOptions = Diskopts
'Crystal Report file does not contain a direct filename property, so you can't specify the file name saved directly.
'So you have to use the DiskFileDestinationOptionOptions object, set its diskfilename properties
'For the path you want, finalize the DestinationSoptions attribute of the crystal report as the above DISKFILEDESTINATIONOTIONOption
myreport.export ()
'The code above will complete the export work.
End Sub
Export Crystal Reports using a PUSH mode
When the exported report is established by the PUSH mode, the first step is to establish a connection and assemble the DataSet, set the setDataSource attribute of the report. Then there is a PULL mode in the steps below.
[/ Html]
Top Reply to: FoxToo (Alibaba and forty stolen) () reputation: 100 2003-6-10 23:06:08 Score: 0 .NET environment Crystal Report Summary
Crystal report is an excellent report development tool. When you develop a general management system, all reports use crystal reports. It is simple, easy to use and powerful, and the author is loved, and the use of crystal reports will be presented to everyone.
First, when using the own crystal report, please register, otherwise you can only use 30 times.
Crystal Report Registration Code
Registration number: 6707437608
Password: AAP5GKS0000GDE100DS
Second, use CrystalReportViewer to preview
The CrystalReportViewer control allows you to view Crystal Report in your application. The ReportSource property is used to set which report to see. After this property setting, the report is displayed in the viewer. The source of the report can be the pathDocument, the path of the report file, or a strong type report. 1. Open Toolbox and drag a CrystalReportViewer to the form and we name RPTVEW.
2. Adjust the Windows Form View to the desired size and move it to the desired position by dragging operation.
3. When running the application, the report will be displayed in the viewer.
Third, create new reports
1. Point "Add" and click Add New Item.
2. In the Add New Items dialog box, select Crystal Report from the Template area, name RPTClient, click Open.
3. In the Crystal Report library, choose one of the following options:
· Use report experts - Guide you to complete the creation process of the report and add your choice to Crystal Report Designer.
· As a blank statement - open the Crystal Report Designer.
· From the existing report - create a new report, which is the same as the designated other report.
Note that the Crystal Report library contains many experts to guide you to complete the creation of several specific types of reports. You may want to use an expert to create an initial report to determine which report construct method is suitable for your needs.
4. Click the "OK" button.
If you choose to use the Report Expert, the Report Experts dialog box appears and has a data resource manager. Select the required data for each folder, complete the operations on the Interface of the Report Experts, and then click Finish to access Crystal Report Designer and your report.
Fourth, is it necessary to dynamically set the data source?
Crystal Reports is connected to a database via a database driver. Each driver is written to handle specific database types or database access technologies.
Pull and push model
In order to provide developers with the most flexible data access method, the Crystal Reports database driver is designed to provide a pull-up and push model that can provide data access.
Pull-up type
In the scaffold, the driver will connect to the database and "pull" "to" "" "as needed. When using this model, the SQL commands that are connected to the database and the SQL commands executed in order to obtain data are also processed by the Crystal Reports itself, and the developer is required to write code. Use the pull model if you do not need to write any special code at runtime.
Push model
Instead, the push model requires the developer to write code to connect to the database, execute the SQL command to create a recordset or data set that matches the fields in the report, and passes the object to the report. This method allows you to share the connection into the application and filter data before Crystal Reports receives data.
Fourth, from the ADO.NET data set production report
Create a dataset object from the database
1. Create a new architecture file in the project:
a. In the Solution Explorer, right click on the project name, point to Add, and then click Add New Item.
b. In the "Category" area of the Add New Item dialog, expand the folder, then select "Data".
c. Select "Data Set" in the Template area.
d. Accept the default name dataset1.xsd.
This creates a new architecture file (DataSet1.xsd), which will use it to generate strong type datasets. The architecture file will be displayed in the ADO.NET Dataset Designer.
2. Specify the database location: a. In the Server Explorer, right-click "Data Connection" and select Add Connection.
b. In the Data Link Properties dialog box, click the Provider tab and select a provider (such as Microsoft Ole DB Provider for SQL Server).
c. Click the Connection tab and specify where your database is located. Enter the server and login information in the desired position.
d. Click the "OK" button.
At this point, your database and its tables and fields appear under the "Data Connection" node of the Server Explorer.
3. In the Solution Explorer, double-click DataSet1.xsd (if it is not an activity view).
DataSet1.xsd should now be displayed in the Dataset tab.
4. To establish a schema for the Data Set, drag the required tables from the Server Explorer to the Dataset1.xsd "Datase" tab.
5. Click "Save Dataset1.xsd" to save the "DataSet1.xsd" file.
6. On the Generate menu, click Generate to generate a dataset object for the project.
ADO.NET Dataset Object provides data description, from it to Crystal Report adds a table. Add a table from the ADO.NET dataset object using the "Database Expert" in Crystal Report Designer.
Please call "Database Expert" when you use the Report Experts to create a new report. Alternatively, to access the "Database Expert" from a report that has already been established using ADO.NET, right-click in Report Designer, point to "Database", and then click Add / Remove Database.
Connect the report to the ADO.NET dataset object
1. In the Database Expert, expand the Project Data folder.
2. Expand the "ADO.NET Dataset" folder.
3. Select the desired data set object.
For example, if it is used at the time of the architecture file "Dataset1.xsd" from the project "WindowsApplication1" schema file, "WindowsApplication1.DataSet1" should be selected.
4. Select the table you want to add to the report and use other data sources.
5. Dynamically change the code of the data source
DIM DSDataSet As New Dataset ()
Dim orpt as new rptclient () 'established report RPTCLIENT
Please read the reader to fill the data set on your own DSDataSet
'Use the Report Engine Object Model to pass the data set to the report
ORPT.SETDATASOURCE (DSDataSet.tables (0))
'Bind the report object with data to the Windows Form Viewer, RPTVEW (CrystalReportViewer Control)
RPtVew.Reportsource = ORPT
Note that the FillDataSet method can connect to the specified database, extract the data, and disconnect the database connection. If you want to add multiple tables in the database to the report, use the SQL JOIN statement to connect these tables together; then specify a result table in the FillDataSet method
6. Creating a master from a report
In the report, there are many reports that the primary slave table structure, such as orders and order items, the order is a record in a table, and the entry is a plurality of records in another table, and the two tables are associated with one field. This report can be implemented using its packet function.
1. New project
2. Add a CrystalReportViewer control to Form1 3. Connect to the Northwind database connected to SQL Server 2000 in the Service 噐 Explorer.
4. Add a dataset DataSet1 to add the Orders and Order Details in the Server Explorer to the data set.
5. Add a crystal statement, use the report expert, select "ADO.NET Dataset" in the project data, insert table Order Details, "Link" is the link to the associated field, in the Field, select The fields of the primary table and the schedule, the selection group in the group is based on the Orders Table ORDERSID field, the total, chart, and select (screens), the style (which can be set), can be set. After setting, click Finish.
6. Adjust the position, width of the field that needs to be displayed in the report designer.
7. Add code in the window.
Private Sub Form1_Load (Byval E AS System.Object, Byval E AS System.Eventargs) Handles MyBase.Load
Dim ORPT AS New CrystalReport1 ()
DIM DSDataSet As New Dataset1 ()
Dim cn as new data.sqlclient.sqlConnection ("data source = pmserver; initial catalog = northwind; user ID = sa; password = sa")
Cn.open ()
Dim daorders as new data.sqlclient.sqldataadapter ("SELECT * from Orders", CN)
Daorders.Fill (DSDataSet, "Orders")
Dim Dadetails as new data.sqlclient.sqldataadapter ("Select * from [Order Details]", CN)
Dadetails.Fill (DSDataSet, "Order Details")
'Use the Report Engine Object Model to pass the data set to the report
ORPT.SetDataSource (DSDataSet)
CrystalReportViewer1.Reportsource = ORPT
End Sub
8, run the program
7. Use the program to change the text of the text in the report.
code show as below:
DIM GetTextObject As TextObject
'Get the ReportObject by name, convert it to TextObject, and return this object.
GetTextObject = ORPT.ReportDefinition.reportObjects.Item ("text13")
GetTextObject.text = "xxxx system"
Summary: The crystal statement has a very powerful function, and can also perform files such as Word, Excel, RTF, which can also generate complex, beautiful charts, are weapons developed by Web and Windows reports.
(Some of this article from MSDN)
Author: Li Honggen
E-mail: lihonggen0@163.com
Top Reply to: foxtoo (Alibaba and forty stolen) () reputation: 100 2003-6-10 23:07:11 Score: 0 I have the following ideas:
1. Get the SQL database related data by connecting the query; 2, placed in the DataSet;
3, call crystal reports (linear or cylindrical templates), generate reports;
4. Output to generate an Excel document.
Ask you the heroes, how to achieve the above ideas? (If there is an example, it is better)
thank you very much!
-------------------------------------------------- -------------
1. Add a new project DataSet to your project, link the database, the required data sheet or pre-depiction
Drake into this Dataset, compile DataSet
2. Crystal Report comes with VS.NET to establish a report as DataSet
3. Push the data in this report in the program
4. Crystal Report has an option to output an Excel and can be implemented by programs
DIM CONN As SqlConnection
DIM DA As SqldataAdapter
DIM STRSQL AS STRING
CONN = New SqlConnection ()
Conn.connectionstring = "User ID = sa; pwd = 1234; data source = xxxx; initial catalog = xxxxx"
Conn.open ()
strsql = "SELECT * from TableName"
Da = New SqldataAdapter (strsql, conn)
DIM DS AS New DataSet ()
Da.fill (DS, "TableName")
DIM RPTDOC AS New ReportName ()
RPTDoc.SetDataSource (DS)
'Specify data for RPTDOC,
CrystalView1.Reportsource = rptdoc 'Specifies the data to CrystalView
CrystalView1.DATABIND ()
CONN.CLOSE ()
5. If you need to display the field associated with multiple tables, it is best to establish a DataSet in the stored procedure.
-------------------------------------------------- -------------
Please refer to the following code:
String strconn = connection string;
SqlConnection myconn = new sqlConnection (STRCONN);
String strcmd = @ "SELECT statement";
SQLCommand mycmd = new sqlcommand (strcmd, myconn);
Sqldataadapter myda = new sqldataadapter (strcmd, myconn);
DataSet myds = new dataset ();
Myconn.open ();
Myda.Fill (MYDS, "Report Name");
Report name myrpt = new report name ();
Myrpt.SetDataSource (MYDS);
this.crystalReportViewer1.reportsource = Myrpt;
Export to Excel:
Myrpt.ExportOptionS.exportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
myrpt.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel; CrystalDecisions.Shared.DiskFileDestinationOptions opt = new CrystalDecisions.Shared.DiskFileDestinationOptions ();
Opt.diskFileName = @ "file name";
Myrpt.ExportOptions.DestinationOptions = OPT;
Myrpt.export ();
Top Reply: Tensun (I want to learn .Net) () Reputation: 100 2003-6-10 23:15:12 Score: 0 Crystal Report 9 Chinese Help Download:
http://www.orrfly.com/download/download.aspx
http://www.enwell.net/soft/
http://www.fast8.com/news.asp
Crystal Reports for Visual Studio .NET
Please refer to PictureObject member
PictureObject class | Crystaldecisions.crystalReports.Engine namespace
Public instance attribute
Border (inherited from ReportObject) Border. Get the Border object.
Height (inherited from ReportObject) INT32. Gets or sets the height of the object with a stone.
Kind (inherited from ReportObject) ReportObjectkind. Get the type of report object.
LEFT (inherited from ReportObject) INT32. Gets or sets the top left corner of the object in the 缇.
Name (inherited from ReportObject) strings. Get the object name.
ObjectFormat (inherited from ReportObject) ObjectFormat. Get the ObjectFormat object.
TOP (inherited from ReportObject) INT32. Gets or sets the top position of the object with the oint.
Width (inherited from ReportObject) INT32. Gets or sets the object width of the 缇.
See
PictureObject class
Imports crystaldecisions.crystalReports.Engine
DIM PicoBject As PictureObject
Picobject = ORPT.ReportDefinition.reportObjects.Item ("Picture1")
Top Reply: Tensun (I want to learn .Net) () Reputation: 100 2003-6-10 23:17:24 Score: 0 From: http://expert.9cbs.net/expert/topic/1896/1896874. XML? Temp = .78677
Everyone uses a crystal statement based on WebForm, if it is simple to follow online "A knife", it will definitely prompt you: landing failed.
For this problem, I spent a whole day to study the help document of the crystal report, and finally get the solution.
I am not a conservative person, I believe there are many netizens who are spending with me in studying this problem. I don't want everyone to spend energy as me as me.
Below is a few steps I implemented. Don't worry, slowly look at you will have a lot of help. Step 1: Look at the sample file
The crystal report comes with an example file, the database is Access (without password). I first run the sample file (webform and winform) results show the correct report, as examples of "flying knives".
So I built a report file and .aspx file, the result shows that the landing failed! But I convert the report file to an example report file, no longer an error.
Where is the problem? Is it a report format file about login privilege? By tracking, debugging, I compare my report files and sample report files without discovering any differences. It seems that the problem is not in the report file.
Is the problem of a database? I created an Access result or landable to fail!
Not a database problem (my own database is unparalleled access, the database in the help)? Nor is the problem of report format file (I carefully analyze the original code of the two)?
So where is the problem? I can't understand!
Step 2: Find a help file
So I once again help. I all over all over the crystal report, I finally found "Access Secure Database [C #]" words, found that there is a paragraph below:
Accessing the secure database through the Crystal Reports for Visual Studio .NET is different between web forms and Windows forms. In the Windows Form, the dialog is automatically prompted to enter the username and password (the test is easy). In a web form, you need to design a form to get this information from the user. For both cases, you can use code to specify usernames and passwords, providing the same security level for all users of the application.
So I am the same database (first use the Access database in the help example, then use the Access database created by yourself). Discovering the same report file, for Winform can show success, and for WebForm still display login failure! So I a little understanding!
It seems that the problem is on the setting of permissions.
Step 3: Research help, finally succeeded!
In the help I found the words "Setting Database Login Parameters", provided some information that later discovered is very useful:
The following example shows how to pass the login parameters into the table of the report. This example uses a connection to a secure SQL Server database.
Start a new project
Add a "button" and four "text box" controls to the form.
Name the "text box" control, respectively: ServerNametXT, DBNametXT, UserNametxt, and Passwordtxt.
Double-click the "Button" control to specify the code of the Click event. Insert the appropriate code according to the language used.
[C #]
// Declare the required variables.
TablelogonInfo LogonInfo = New TablelogonInfo ();
INT i = 0;
// loop in turn on each table in the report.
For (i = 0; i == Report.database.tables.count - 1; i )
{
/ / Set the connection information of the current table.
Logoninfo.connectioninfo.servername = ServerNametxt.Text;
Logoninfo.connectioninfo.databaseName = dbnametxt.text;
Logoninfo.connectioninfo.userid = usernametxt.text; Logoninfo.connectioninfo.Password = passwordtxt.text;
Report.Database.tables [i] .applylogonInfo (LogonInfo);
}
Note that the password-protected Microsoft Access and Paradox and other PC databases also use this method, but logoninfo.servername and Logoninfo.databaseName are left empty.
So I like this, try it, an error message: No TablelogonInfo and Report were found.
Later I found that TablelogonInfo is a member belonging to the CrystalDecisions.Shared namespace. So I added a reference:
USING CRYSTALDECISIONS.SHARED;
This issue appears in Report.
REPORT? What is something, I have all the help, there is no such function or class!
[honestly! This problem is hard to have a long time! I have been looking for Report to something! The water view company is really, help, don't write more than a matter! This is! ! ! ]
Eventually I finally found that the Report is just a user-defined object, not the object of the system itself.
When I was confused, I suddenly thought, why not look at the Database behind the Report, what is something, finally solved, find the following information in the help
ReportDocument ORPT = New ReportDocument ();
Report belongs to the member of the DocumentCrystaldecisions.crystalReports .Engine class.
Modifying code: Adding a reference
Using crystaldecisions.shared; // Responsible for explaining TableLogonInfo class
Using crystaldecisions.crystalreports .Engine; // Responsible for explaining ReportDocument Class Private Void Page_Load (Object Sender, System.EventArgs E)
{
TablelogonInfo LogonInfo = New TablelogonInfo ();
/ / Here, a ReportDocument object REPORT must be applied in advance, and the data report is loaded.
ReportDocument ORPT = New ReportDocument ();
ORPT.LOAD ("c: //inetpub//wwwroot/ //exer/pagelet//crystal//cr1.rpt"); // Modify it to your self //'s correct position
// Establish security information
// Password protected Microsoft Access and Paradox, etc. PC databases, but logoninfo.servername // and logoninfo.databaseename want to keep empty
LogonInfo.connectioninfo.servername = "www";
Logoninfo.connectioninfo.databaseName = "Archives";
Logoninfo.connectioninfo.userid = "sa";
LogonInfo.connectioninfo.password = "123456";
ORPT.Database .Tables [0] .applylogonInfo (LogonInfo); // Establish a connection between .RPT files and CrystalReportViewer files
CrystalReportViewer1.Reportsource = ORPT;
}
Report files have finally appeared!
Wow, I am so happy, I can't stop standing up and stretched a lazy waist!
Step 4: The final full version of the code
The above code does not have system expansion and flexibility. There are two shortcomings:
(1), the data report format file is an absolute path
(2) Once the setting of database access is set, it is unmodable in the final release, especially the customer's SQL Server server is not like the program environment you debug.
Based on this consideration. Introducing two more good things:
(1), Server.mappath function
(2) Read web.config (this example also tells you how to operate the web.config configuration file)
The final revision is as follows: (full code) database is SQL Server2000
Using crystaldecisions.shared; // Responsible for explaining TableLogonInfo class
Using crystaldecisions.crystalreports .Engine; // Responsible to explain the ReportDocument class
Private Void Page_Load (Object Sender, System.EventArgs E)
{
TablelogonInfo LogonInfo = New TablelogonInfo ();
/ / Here, a ReportDocument object REPORT must be applied in advance, and the data report is loaded.
ReportDocument ORPT = New ReportDocument ();
// Get the true path of the.rpt file
String path1, path2;
Path1 = Server.mappath ("// EXER // Pagelet");
Path2 = Path1 "// Crystal // Cr1.rpt";
//orpt.load ("c://inetpub//wwwroot//exer/pagelet//crystal//cr1.rpt ");
ORPT.LOAD (PATH2);
/ / Get the logonInfo parameter information from Web.config
String A, B, C, D;
// Get servername
A = system.configuration .configurationSettings .appsettings ["servername"];
/ / Get DatabaseName
B = system.configuration .configurationSettings .Appsettings ["Database"];
// Get userid
C = system.configuration .configurationSettings .Appsettings ["userid"];
/ / Get password
D = system.configuration .configurationSettings .Appsettings ["pass"];
// Set the logonInfo parameter
Logonifo.connectioninfo.servername = a;
LogonInfo.connectioninfo.databaseName = B;
Logoninfo.connectioninfo.userid = C; logoninfo.connectioninfo.password = D;
ORPT.DATABASE .TABLES [0] .applylogoninfo (logonfo);
// Establish a connection between the.rpt file and the CrystalReportViewer file.
CrystalReportViewer1.Reportsource = ORPT;
}
Operation procedure for the entire presentation:
1. In the Solution Explorer, you need to store the report file, add new items: CrystalReport report, named CR1.RPT
2. When selecting a data source in the Subsequent Report Experts, be sure to select OLE DB, then select the drive engine that responds according to your database:
SQL Server: Microsoft Ole DB Provider for SQL Server
Access: Microsoft Jet.4.0
3, enter the correct database connection, this step will not be wrong without anything!
4, establish a data report, and save the CR1.RPT file
5. Open WebForm1.aspx. Add CrystalReportViewer Control: Name: CrystalReportViewer1
6, add the above code in the Page_Load event in WebForm1.aspx.cs:
(Note: Don't forget to quote!)
*********************************************************** ***
Here is the details related to this content in web.config
appsettings>
*** Note that
/ / Get password
D = system.configuration .configurationSettings .Appsettings ["pass"]; here
"PASS" in AppsetTings ["pass"] is consistent. Of course, the name can be casual, but must be consistent
*********************************************************** ******************
Transfer from www.chinaspx.com
Author: ydmwy
Top Reply: Tensun (I want to learn .Net) () Reputation: 100 2003-6-10 23:20:20 Score: 0 The above post solves the database with password, crystal report tips: login failure! ! (If the database has no password, there is no problem !!)
Top Reply to: efyrose (Walking Fish) () Reputation: 100 2003-6-11 9:21:37 Score: 0 You are all good, touched ing. Top Reply to: Chyich () () Reputation: 100 2003-6-11 9:50:54 Score: 0 Up
Top Reply to: wen98091 (天蓝 瓜子) () Reputation: 100 2003-6-11 9:52:22 Score: 0 THX
Top Reply to: XHDAI1 (Pioneer) () Reputation: 100 2003-6-11 11:02:05 Score: 0 Chinese Help of Crystal Report 9
http://www.orrfly.com/download/download.aspx
How can I enter the login when downloading? What is the password of the username?
Top Reply to: efyrose (Walking Fish) () Reputation: 100 2003-6-11 11:03:32 Score: 0 Ask, why I added a DataSet, drag into a table in the database, then point to generate, When adding a blank statement, add a database to the report, pop-up the database expert, select the ADO.NET dataset in the project data. Licening my Dataset1, however, click on DataSet1 to expand him, next level prompt ".. no items found." Cannot be added to the report in the report, hoped with Multi-advice
Top Reply to: Fengxin107 (chasing rainbow) () Reputation: 100 2003-6-11 11:10:14 Score: 0 See ing ...
Top Replyee: liuketao111 () reputation: 64 2003-6-11 11:38:16 Score: 0 Ask a few masters on the building, I have recently installed CrystalReport, the following error, I don't know how to deal with, please help !
Description: An error occurred during the process of compiling to the request to provide the resource required. Please check the following specific error details and modify the source code appropriately.
Compiler error message: CS1595: "CrystalDecisions.Web.crystalReportViewer" is already defined in multiple places; use "c: /winnt/assembily/gac/crystaldecisions.web/9.1.300.0__692fbea5521e1304/crystaldecisions.web.dll" definition
Source error:
Row 14: