Reputation: 783
I have created a simple report in crystal reports designer version 14, it consists of two tables just a straight link from one to another. when i run the report in the designer i get different values from when i run the report in a crystal report viewer. I thought it was cashing the data somewhere but the report is set not to store the data.
private void btnLoad_Click(object sender, EventArgs e)
{
reportDocu = new ReportDocument();
TableLogOnInfo tableLogoninfo = new TableLogOnInfo();
ConnectionInfo connectionInfo = new ConnectionInfo();
Tables CrTables;
reportDocu.Load(@"Inventory.rpt");
var crTables = reportDocu.Database.Tables;
connectionInfo.UserID = "user";
connectionInfo.Password = "pass";
CrTables = reportDocu.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
tableLogoninfo = CrTable.LogOnInfo;
tableLogoninfo.ConnectionInfo = connectionInfo;
CrTable.ApplyLogOnInfo(tableLogoninfo);
}
crystalReportViewer1.ReportSource = reportDocu;
crystalReportViewer1.Update();
crystalReportViewer1.Refresh();
}
I have looked in the report and i have ticked (using the designer within VS) Design - Default Settings - Reporting - Discard saved data when loading reports.
The report uses a ODBC for a i-series
I have no idea where this data is coming from when the report is run?
Upvotes: 1
Views: 962
Reputation: 186
You Should use dataset and drag your table into the dataset
After that you should try this code I always use this code :-
using System.Data;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
public partial class Student_Report : System.Web.UI.Page
{
SqlConnection cn;
// SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
string str = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString();
cn = new SqlConnection(str);
cn.Open();
da = new SqlDataAdapter("select * from StudentReg_mst", cn);
ds = new DataSet();
da.Fill(ds, "StudentReg_mst");
ReportDocument rd = new ReportDocument();
rd.Load(Server.MapPath("StudentReport.rpt"));
rd.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rd;
CrystalReportViewer1.DataBind();
}
Hope this will help you
Upvotes: 1