Using Crystal statements under ASP.net

Source: Internet
Author: User
Tags join ole tostring
Asp.net| Crystal Report summary as follows:

1. The first step is to add a new item CrystalReport1

2. Right-click on the Crystalreport1.rpt face page: "Database" à "Add/Remove Database" appears in the following dialog box:

Then click the plus sign of OLE DB (ADO) to eject the dialog box for the Select database

The "Current Connection" in "Project Data" displays OLE DB (ADO) connections. This allows you to add a table to the selected table on the right (remember: Do not select a table or command from "OLE DB" again from "current connection," If you use a dataset, the same thing, Otherwise all hint out "Landing failure" Error!)

3. Field data Manager inside the database field, drag the field directly into the crystalreport.rpt. Layout well.

4. Back to the WebForm1.aspx page, select the control crystalreportviewer to place it on the page.

5. Code

Using Crystaldecisions.shared;

Using CrystalDecisions.CrystalReports.Engine;

Add code to WebForm1.aspx.cs's Form_Load:

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;

which

The TableLogOnInfo class is: Provides properties for retrieving and setting table join options. It has a connection to the attribute ConnectionInfo, Used to set up a connection to the database. Generate a report document object to give it the crystalreport1.rpt that we do well in front of it. Here is the Database property! The report object is then made as a CrystalReportViewer1 data source.

Alternatively, the method of obtaining the database is changed to get the dataset directly from the database

Using System.Data.SqlClient;
Using System.Collections.Specialized;

String strconn=system.configuration.configurationsettings.appsettings["DB"]. ToString ();
using (SqlConnection conn = new SqlConnection (strconn))
{
SqlDataAdapter da = new SqlDataAdapter (strsql,conn);//strsql is SQL language "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 to WebForm1.aspx.cs's Form_Load:

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;

which

The TableLogOnInfo class is: Provides properties for retrieving and setting table join options. It has a connection to the attribute ConnectionInfo, Used to set up a connection to the database. Generate a report document object to give it the crystalreport1.rpt that we do well in front of it. Here is the Database property! The report object is then made as a CrystalReportViewer1 data source.

Alternatively, the method of obtaining the database is changed to get the dataset directly from the database

Using System.Data.SqlClient;
Using System.Collections.Specialized;

String strconn=system.configuration.configurationsettings.appsettings["DB"]. ToString ();
using (SqlConnection conn = new SqlConnection (strconn))
{
SqlDataAdapter da = new SqlDataAdapter (strsql,conn);//strsql is SQL language "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 to WebForm1.aspx.cs's Form_Load:

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;

which

The TableLogOnInfo class is: Provides properties for retrieving and setting table join options. It has a connection to the attribute ConnectionInfo, Used to set up a connection to the database. Generate a report document object to give it the crystalreport1.rpt that we do well in front of it. Here is the Database property! The report object is then made as a CrystalReportViewer1 data source.

Alternatively, the method of obtaining the database is changed to get the dataset directly from the database

Using System.Data.SqlClient;
Using System.Collections.Specialized;

String strconn=system.configuration.configurationsettings.appsettings["DB"]. ToString ();
using (SqlConnection conn = new SqlConnection (strconn))
{
SqlDataAdapter da = new SqlDataAdapter (strsql,conn);//strsql is SQL language "select * from Dbo.table1"
DataSet ds=new DataSet ();
Da. Fill (DS);
CrystalReport1 CR1 = new CrystalReport1 ();
CR1. Setdatasource (DS);
Crystalreportviewer1.reportsource = CR1;

}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.