String SQL = "select * from orders ";
String dbconfig_ SQL = @ "Data Source = WAN-9013A0BB35C \ sql2005; initial catalog = northwind; user id = sa ";
Dataset DS = new dataset ();
Sqlconnection sqlcon = new sqlconnection (dbconfig_ SQL );
Sqlcommand sqlcmd = new sqlcommand (SQL, sqlcon );
Sqldataadapter sqglad = new sqldataadapter ();
Sqglad. selectcommand = sqlcmd;
Sqglad. Fill (DS, "orders ");
Crystalreportsource1.reportdocument. Load (server. mappath ("crystalreport. rpt "));
// Note that the name of the table in dataset must be specified here. Otherwise, the system prompts "the report you requested requires more information ."
Crystalreportsource1.reportdocument. setdatasource (Ds. Tables ["orders"]);
//{?} You do not need to assign values to parameters in, even if a value is assigned.
Crystalreportsource1.reportdocument. parameterfields ["parm"]. currentvalues. addvalue ("1234567 ");
Crystalreportsource1.reportdocument. parameterfields ["title"]. currentvalues. addvalue ("sample report in Push mode! ");
Crystalreportsource1.databind ();
Crystalreportviewer1.reportsource = crystalreportsource1;
Crystalreportviewer1.databind ();
Summary:
Connect to the database, SQL string, or write a stored procedure by yourself.
Fill Dataset
Report viewer obtains reportdocument objects and extracts data from reports.
Pass dataset data to the Report Engine