[英]How to generate crystal report in ASP.net C# using visual studio 2012?
I just recently installed Visual Studio 2012, everything's working good with 2010 with my Crystal report but when I migrated the code to 2012 I can't display anything. 我刚刚安装了Visual Studio 2012,在我的Crystal报表中,一切都与2010兼容,但是当我将代码迁移到2012时,我什么也无法显示。 Can you pls check if there is something I'm missing with this code:
您能否检查一下此代码是否缺少某些内容:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection cnn;
string connectionString = null;
string sql = null;
connectionString = "data source=server; initial catalog=DBO;user id=sa; password= passw0rd";
cnn = new SqlConnection(connectionString);
cnn.Open();
sql = "select BadgeNo as DataColumn1,Name as DataColumn2, Section as DataColumn3 from Safety where ID = '24'";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
cnn.Close();
DataSet1 ds = new DataSet1();
dscmd.Fill(ds, "DataTable1");
ReportobjRpt = new Report1 ();
objRpt.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = objRpt;
CrystalReportViewer1.RefreshReport();
}
I am using a dataset to transfer data from the SQL server to crystal report. 我正在使用数据集将数据从SQL Server传输到Crystal报表。 Please help.
请帮忙。 Thank you.
谢谢。
Try this way: 尝试这种方式:
using CrystalDecisions.CrystalReports.Engine;
public partial class Default2 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(“Connection String “);
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
ReportDocument rpt = new ReportDocument();
rpt.Load(Server.MapPath("~/CrystalReport.rpt"));
SqlCommand cmd = new SqlCommand("Select * from Raj_Table[tbl_name]", con);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = cmd;
da.Fill(ds, "Raj_Table[TableName]");
rpt.SetDataSource(ds);
con.Close();
CrystalReportViewer1.ReportSource = rpt;
CrystalReportViewer1.DataBind();
}
}
It will help you. 它会帮助你。
This code will help you: 此代码将帮助您:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection cnn;
string connectionString = null;
string sql = null;
connectionString = "data source=server; initial catalog=DBO;user id=sa; password= passw0rd";
cnn = new SqlConnection(connectionString);
cnn.Open();
SqlCommand com = new SqlCommand("select BadgeNo as DataColumn1,Name as DataColumn2, Section as DataColumn3 from Safety where ID = '24'", conn);
adap.SelectCommand = com;
adap.Fill(tables);
ReportDocument doc;
myreport.SetDataSource(tables);
doc = new ReportDocument();
doc.Load(Server.MapPath("RptName.rpt"));
myreport.ReportSource = doc;
myreport.ReportSource = myreport;
}
You are referencing the object objRpt
instead of ReportobjRpt
which is already created. 您引用的是对象
objRpt
而不是已创建的ReportobjRpt
。
Try this one: 试试这个:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection cnn;
string connectionString = null;
string sql = null;
connectionString = "data source=server; initial catalog=DBO;user id=sa; password= passw0rd";
cnn = new SqlConnection(connectionString);
cnn.Open();
sql = "select BadgeNo as DataColumn1,Name as DataColumn2, Section as DataColumn3 from Safety where ID = '24'";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
cnn.Close();
DataSet1 ds = new DataSet1();
dscmd.Fill(ds, "DataTable1");
ReportobjRpt = new Report1 ();
ReportobjRpt.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = ReportobjRpt;
CrystalReportViewer1.RefreshReport();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.