1、添加新项->Reporting->CrystalReport1.rpt
2、CrystalReport1.rpt这里大家慢慢摸索
3、建立一个webform1.spx页面,工具箱中拖入CrystalReportViewer到页面中
4、webform1.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
ReportDocument oRpt = new ReportDocument();
string RptDir=Server.MapPath("CrystalReport1.rpt");
oRpt.Load(RptDir);
DataSet1 ds = new DataSet1();
//获得数据
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TestDBConnectionString"].ConnectionString);
SqlCommand command = conn.CreateCommand();
command.CommandType = CommandType.Text;
command.CommandText = "SELECT * FROM Table1";
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(ds.Table1);
oRpt.SetDataSource(ds);
CrystalReportViewer1.ReportSource = oRpt;
}