Transfer from http://202.102.240.86/~fjw/mystudy/crystal.htm
Abstract is as follows:
1. The first step is to add new items CrystalReport1
2. Right click on the CrystalReport1.rpt page: "Database" à "Add / Remove Database" The following dialog box:
Then open the OLE DB (ADO) plus, and the dialog box will be ejected.
The "current connection" in "Project Data" is displayed by OLE DB (ADO), so you can add a table to the "selected table" on the right (remember: do not elect "OLE DB" The table or command is also selected from the "Current Connection". If you use the data set, it is the same reason, otherwise it will prompt the "landing failed" error!)
3. Field Data Manager Drag the field directly to the CrystalReport.rpt. Place the layout.
4. Go back to the WebForm1.aspx page, select the control CrystalReportViewer to put it on the page.
5. Code
USING CRYSTALDECISIONS.SHARED;
Using crystaldecisions.crystalreports.Engine;
Add code in Form_Load in WebForm1.aspx.cs:
TablelogonInfo LogonInfo = New TablelogonInfo ();
ReportDocument rpdmy0 = new reportDocument ();
LogonInfo.connectioninfo.servername = "nnn";
Logoninfo.connectioninfo.password = "dong";
Logoninfo.connectioninfo.databaseName = "lab";
Logoninfo.connectioninfo.userid = "sa";
String path = server.mappath ("crystalreport2.rpt");
RPDMY0.LOAD (PATH);
RPDMY0.Database.tables [0] .applylogoninfo (LogonInfo);
CrystalReportViewer1.Reportsource = rpdmy0;
among them:
The TableLogonInfo class is: Provide an attribute to retrieve and set the table connection option. It has a connection-connected property ConnectionInfo to set the connection with the database. As above, ServerName, etc. Generate a report document object, the CrystalReport1 we do before. .rpt assigned it. It is important to pay attention to the Database property! Then use the report object as the data source of CrystalReportViewer1.
Or, the method of obtaining the database is changed to get DataSet directly from the database.
Using system.data.sqlclient; using system.collections.specialize;
. String strConn = System.Configuration.ConfigurationSettings.AppSettings [ "DB"] ToString (); using (SqlConnection conn = new SqlConnection (strConn)) {SqlDataAdapter da = new SqlDataAdapter (strSQL, conn); // strSQL SQL language is " Select * from dbo.table1 "DataSet DS = New Dataset (); DA.FILL (DS); CrystalReport1 cr1 = new crystalReport1 (); cr1.setDataSource (DS); CrystalReportViewer1.Reportsource = CR1;}
USING CRYSTALDECISIONS.SHARED;
Using crystaldecisions.crystalreports.Engine;
Add code in Form_Load in WebForm1.aspx.cs:
TablelogonInfo LogonInfo = New TablelogonInfo ();
ReportDocument rpdmy0 = new reportDocument ();
LogonInfo.connectioninfo.servername = "nnn";
Logoninfo.connectioninfo.password = "dong";
Logoninfo.connectioninfo.databaseName = "lab";
Logoninfo.connectioninfo.userid = "sa";
String path = server.mappath ("crystalreport2.rpt");
RPDMY0.LOAD (PATH);
RPDMY0.Database.tables [0] .applylogoninfo (LogonInfo);
CrystalReportViewer1.Reportsource = rpdmy0;
among them:
The TableLogonInfo class is: Provide an attribute to retrieve and set the table connection option. It has a connection-connected property ConnectionInfo to set the connection with the database. As above, ServerName, etc. Generate a report document object, the CrystalReport1 we do before. .rpt assigned it. It is important to pay attention to the Database property! Then use the report object as the data source of CrystalReportViewer1.
Or, the method of obtaining the database is changed to get DataSet directly from the database.
Using system.data.sqlclient; using system.collections.specialize;
. String strConn = System.Configuration.ConfigurationSettings.AppSettings [ "DB"] ToString (); using (SqlConnection conn = new SqlConnection (strConn)) {SqlDataAdapter da = new SqlDataAdapter (strSQL, conn); // strSQL SQL language is " Select * from dbo.table1 "DataSet DS = New Dataset (); DA.FILL (DS); CrystalReport1 cr1 = new crystalReport1 (); cr1.setDataSource (DS); CrystalReportViewer1.Reportsource = CR1;}
USING CRYSTALDECISIONS.SHARED;
Using crystaldecisions.crystalreports.Engine;
Add code in Form_Load in WebForm1.aspx.cs:
TablelogonInfo LogonInfo = New TablelogonInfo ();
ReportDocument rpdmy0 = new reportDocument ();
LogonInfo.connectioninfo.servername = "nnn";
Logoninfo.connectioninfo.password = "dong";
Logoninfo.connectioninfo.databaseName = "lab";
Logoninfo.connectioninfo.userid = "sa";
String path = server.mappath ("crystalreport2.rpt");
RPDMY0.LOAD (PATH);
RPDMY0.Database.tables [0] .applylogoninfo (LogonInfo);
CrystalReportViewer1.Reportsource = rpdmy0;
among them:
The TableLogonInfo class is: Provide an attribute to retrieve and set the table connection option. It has a connection-connected property ConnectionInfo to set the connection with the database. As above, ServerName, etc. Generate a report document object, the CrystalReport1 we do before. .rpt assigned it. It is important to pay attention to the Database property! Then use the report object as the data source of CrystalReportViewer1.
Or, the method of obtaining the database is changed to get DataSet directly from the database.
Using system.data.sqlclient; using system.collections.specialize;
. String strConn = System.Configuration.ConfigurationSettings.AppSettings [ "DB"] ToString (); using (SqlConnection conn = new SqlConnection (strConn)) {SqlDataAdapter da = new SqlDataAdapter (strSQL, conn); // strSQL SQL language is " Select * from dbo.table1 "DataSet DS = New Dataset (); DA.FILL (DS); CrystalReport1 cr1 = new crystalReport1 (); cr1.setDataSource (DS); CrystalReportViewer1.Reportsource = CR1;}