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. 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. 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.
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.