我是.net和C#的新手,我的asp水晶报告不会打印或导出。我已经读过你必须使用会话才能做到这一点。任何人都可以给我任何提示吗?我有一个基本的网页设置,可以让您查看我们的报告并输入参数。这工作正常。每当我尝试打印或导出我的页面开始做某事然后停止,我什么也得不到。有什么建议吗?这是我的代码
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection CN;
String MyConnectionString = null;
MyConnectionString = "data source=srv;initial catalog=db;user id=reports;password=";
CN = new SqlConnection(MyConnectionString);
CN.Open();
string SQL = null;
SQL = "SELECT oeordhdr_sql.ord_no, oeordlin_sql.line_seq_no, oeordlin_sql.qty_to_ship, oeordlin_sql.cus_item_no, imitmidx_sql.upc_cd, imitmidx_sql.item_desc_1, oelincmt_sql.cmt, oeordhdr_sql.ship_to_name, oeordhdr_sql.ship_to_addr_1, oeordhdr_sql.ship_to_addr_2, oeordhdr_sql.ship_to_addr_3, oeordhdr_sql.ship_to_addr_4,sycdefil_sql.cd_type, sycdefil_sql.code_desc FROM(((oeordhdr_sql oeordhdr_sql INNER JOIN oeordlin_sql oeordlin_sql ON( oeordhdr_sql.ord_type = oeordlin_sql.ord_type ) AND( oeordhdr_sql.ord_no = oeordlin_sql.ord_no )) LEFT OUTER JOIN oelincmt_sql oelincmt_sql ON oeordhdr_sql.ord_no = oelincmt_sql.ord_no ) LEFT OUTER JOIN sycdefil_sql sycdefil_sql ON oeordhdr_sql.ship_via_cd = sycdefil_sql.sy_code ) INNER JOIN imitmidx_sql imitmidx_sql ON oeordlin_sql.item_no = imitmidx_sql.item_no WHERE sycdefil_sql.cd_type = 'V' AND oeordhdr_sql.ord_no = ' {?Ord_no}' ORDER BY oeordhdr_sql.ord_no";
SqlDataAdapter myDa = new SqlDataAdapter(SQL, CN);
CN.Close();
DataSet DS = new DataSet();
myDa.Fill(DS, "DataTable1");
ReportDocument myRPT = new ReportDocument();
myRPT.Load(Server.MapPath("~/CrystalReport.rpt"));
myRPT.SetDataSource(DS);
CrystalReportViewer1.ReportSource = myRPT;
}
答案 0 :(得分:0)
事实证明,我需要做的就是添加一个if(!Page.IsPostback)
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
SqlConnection CN;
String MyConnectionString = null;
MyConnectionString = "data source=srv;initial catalog=db;user id=reports;password=";
CN = new SqlConnection(MyConnectionString);
CN.Open();
string SQL = null;
SQL = "SELECT oeordhdr_sql.ord_no, oeordlin_sql.line_seq_no, oeordlin_sql.qty_to_ship, oeordlin_sql.cus_item_no, imitmidx_sql.upc_cd, imitmidx_sql.item_desc_1, oelincmt_sql.cmt, oeordhdr_sql.ship_to_name, oeordhdr_sql.ship_to_addr_1, oeordhdr_sql.ship_to_addr_2, oeordhdr_sql.ship_to_addr_3, oeordhdr_sql.ship_to_addr_4,sycdefil_sql.cd_type, sycdefil_sql.code_desc FROM(((oeordhdr_sql oeordhdr_sql INNER JOIN oeordlin_sql oeordlin_sql ON( oeordhdr_sql.ord_type = oeordlin_sql.ord_type ) AND( oeordhdr_sql.ord_no = oeordlin_sql.ord_no )) LEFT OUTER JOIN oelincmt_sql oelincmt_sql ON oeordhdr_sql.ord_no = oelincmt_sql.ord_no ) LEFT OUTER JOIN sycdefil_sql sycdefil_sql ON oeordhdr_sql.ship_via_cd = sycdefil_sql.sy_code ) INNER JOIN imitmidx_sql imitmidx_sql ON oeordlin_sql.item_no = imitmidx_sql.item_no WHERE sycdefil_sql.cd_type = 'V' AND oeordhdr_sql.ord_no = ' {?Ord_no}' ORDER BY oeordhdr_sql.ord_no";
SqlDataAdapter myDa = new SqlDataAdapter(SQL, CN);
CN.Close();
DataSet DS = new DataSet();
myDa.Fill(DS, "DataTable1");
ReportDocument myRPT = new ReportDocument();
myRPT.Load(Server.MapPath("~/CrystalReport.rpt"));
myRPT.SetDataSource(DS);
CrystalReportViewer1.ReportSource = myRPT;
}
}