Page_Load for Crystal Report [英] Page_Load for Crystal Report
问题描述
我有一个包含CrystalReportViewer的页面,在查看器中有一个报告。我试图使用会话打印报告但到目前为止没有运气。我有一个可能你的代码,但到目前为止我在代码中有错误。这是我第一次在这个级别上使用Crystal Reports。我之前从未参加过会议。这是代码。
I have a page with CrystalReportViewer on it and a report in the viewer. I am trying to print out the report using a session but no luck so far. I have a code that might your but so far I have errors in the code. This is my first time working with Crystal Reports on this level. I never did the sessions on it before. Here is the code.
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Web;
using System.Web.UI.WebControls.WebParts;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml.Linq;
namespace SACSCOCLogin1._1
{
public partial class ReportFormA : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con.Open();
SqlCommand comm = new SqlCommand("SELECT * FROM Table55 where INST_ID=" + Session["INST_ID"].ToString(), con);
comm.CommandType = CommandType.Text; SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = comm;
CrystalReportViewer1 dataset = new CrystalReportViewer1();
adapter.Fill(dataset, "DataTable1");
CrystalReportViewer1.SetDataSource(dataset);
CrystalReportViewer1.ReportSource = crystal;
}
}
}
这是我的地方错误在代码中
This is where my error are in the code
CrystalReportViewer1 dataset = new CrystalReportViewer1();
adapter.Fill(dataset, "DataTable1");
CrystalReportViewer1.SetDataSource(dataset);
CrystalReportViewer1.ReportSource = crystal;
我做错了什么?这可以修复还是我应该走另一条路?
新的更新代码还没有工作但是到了那里。
What am I doing wrong? Can this be fixed or should I go another route?
New Updated code not yet working but getting there.
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con.Open();
SqlCommand comm = new SqlCommand("SELECT * FROM Table55 where INST_ID=" + Session["INST_ID"].ToString(), con);
comm.CommandType = CommandType.Text;
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = comm;
CrystalReportViewer dataset = new CrystalReportViewer();
DataTable dt = new DataTable();
adapter.Fill(dt);
dataset.SetDataSource(dt);
CrystalReportViewer1.ReportSource = new CrystalReportViewer();
推荐答案
另见上面的评论:
这是你可以做的一个例子。
See also my comments above:
Here is an example of what you can do.
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Web;
using System.Web.UI.WebControls.WebParts;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml.Linq;
namespace SACSCOCLogin1._1
{
public partial class ReportFormA : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con.Open();
SqlCommand comm = new SqlCommand("SELECT * FROM Table55 where INST_ID=" + Session["INST_ID"].ToString(), con);
comm.CommandType = CommandType.Text;
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = comm;
CrystalReportViewer dataset = new CrystalReportViewer();
DataTable dt = new DataTable();
adapter.Fill(dt, "DataTable1");
dataset.SetDataSource(dt);
dataset.ReportSource = crystal;
}
}
}
CrystalReportViewer report = new CrystalReportViewer();
adapter.Fill(dataset, "DataTable1");
report.SetDataSource(dataset);
CrystalReportViewer1.ReportSource = crystal;
到目前为止的新代码。下划线是错误仍在的地方。
The new code so far. Where the underline is is where the errors are still.
这篇关于Page_Load for Crystal Report的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!