The crystal report has two modes: pull and push. This article uses the push mode in the web project;
Reports simulate product orders, involving three tables: product, productorder, and client.
1. Create a design-time dataset and establish the link before the table in Database Expert, such:
2. Create a. rpt file and point to the dataset we created earlier. The name is pullcrystalreport3.rpt, for example:
3. Place the Crystal Report viewer control on the. ASPX page.
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "pull3.aspx. CS "inherits =" pull3 "%> <% @ register Assembly =" crystaldecisions. web, version = 10.5.3700.0, culture = neutral, publickeytoken = 692fbea5521e1304 "namespace =" crystaldecisions. web "tagprefix =" cr "%> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
4. Add the following to code behind page:Code:
Dataset DS = new dataset (); sqldataadapter da = new sqldataadapter (); string connectionstr = "Data Source = .; initial catalog = crystalreport; persist Security info = true; user id = sa; Password = 111 "; sqlconnection connection = new sqlconnection (connectionstr ); // set the data source da = new sqldataadapter ("select * from client", connection); DA. fill (DS, "client"); da = new sqldataadapter ("select * from product", connecti On); DA. fill (DS, "product"); da = new sqldataadapter ("select * From productorder", connection); DA. fill (DS, "productorder"); // sets the report document string reportpath = server. mappath ("~ /Pullcrystalreport3.rpt "); reportdocument RPT = new reportdocument (); Rpt. Load (reportpath); Rpt. setdatasource (DS); // specify the data source crystalreportviewer as crystalreportviewer1.reportsource = RPT;
5. The final effect is as follows: