VS2010 Crystal Report Use method _ Practical skills

Source: Internet
Author: User
Create a new Windows Forms Application project in VS2010, add a Crystal Report "Crystalreport1.rpt" to the project, and then click the right mouse button on the item to change the target frame to ". Net Framework 4"



Open the app.config file, a "uselegacyv2runtimeactivationpolicy=" true "property" on the "Startup" node

Copy Code code as follows:

<startup uselegacyv2runtimeactivationpolicy= "true" >
<supportedruntime version= "v4.0" sku= ". netframework,version=v4.0 "/>
</startup>

In the Form1 form, drag a crystal the Viewer control from the toolbox, double-click the Form form, double-click the form form, not crystal the show viewer, and write the following code in the Form_Load event in the background:

Copy Code code as follows:

private void Form1_Load (object sender, EventArgs e)
{
String connstr = "Data source=.\\sqlexpress;initial catalog=dbtest; User Id=sa; Password=test ";
SqlConnection conn = new SqlConnection (CONNSTR);
Conn. Open ();
Try
{
String sql = "SELECT * from Customer where email!= ' test@gmail.com '";
SqlDataAdapter SDA = new SqlDataAdapter (SQL, conn);
DataSet ds = new DataSet ();
Sda. Fill (ds, "tmptable");

String Reportpath = System.Windows.Forms.Application.StartupPath + @ "\crystalreport1.rpt";
Reportdocument rd = new reportdocument ();
Rd. Load (Reportpath);
Rd. Setdatasource (ds. Tables[0]. DefaultView);
This.crystalReportViewer1.ReportSource = rd;
}
catch (Exception ex)
{
throw new Exception (ex. Message.tostring ());
}
Finally
{
Conn. Close ();
}
}

That's OK.

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.