Problem with crystal reports
-
I want to display a crystal report using two tables from sql server but when report loads only header fields are visible no data is getting displayed.I have a textbox and a button on the page.After clicking on the button report should be displayed.RollNo is entered in the box and is common to both the tables.Here is the code:- using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using CrystalDecisions.CrystalReports; using CrystalDecisions.ReportSource; using CrystalDecisions.Web; using CrystalDecisions.CrystalReports.Engine; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = "data source =SHYLOCK2E935FD7F\\SQLEXPRESS;Initial catalog=StudentDetails ;Integrated Security =true"; } protected void btnShow_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = "datasource=SHYLOCK2E935FD7F\\SQLEXPRESS;Initial catalog=StudentDetails ;Integrated Security =true"; SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = "select c.RollNo,c.StudentName,c.Department,p.feetype,p.amount from studentheader c INNER JOIN studentdetails p on p.Rollno=c.Rollno where c.Rollno=" + TextBox1.Text + ""; DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; da.Fill(ds); con.Close(); ReportDocument CrystalReport = new ReportDocument(); string reportPath = Server.MapPath("CrystalReport.rpt"); CrystalReport.Load(reportPath); CrystalReport.SetDataSource(ds); CrystalReportViewer1.ReportSource = CrystalReport; CrystalReportViewer1.DataBind(); } }
-
I want to display a crystal report using two tables from sql server but when report loads only header fields are visible no data is getting displayed.I have a textbox and a button on the page.After clicking on the button report should be displayed.RollNo is entered in the box and is common to both the tables.Here is the code:- using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using CrystalDecisions.CrystalReports; using CrystalDecisions.ReportSource; using CrystalDecisions.Web; using CrystalDecisions.CrystalReports.Engine; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = "data source =SHYLOCK2E935FD7F\\SQLEXPRESS;Initial catalog=StudentDetails ;Integrated Security =true"; } protected void btnShow_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = "datasource=SHYLOCK2E935FD7F\\SQLEXPRESS;Initial catalog=StudentDetails ;Integrated Security =true"; SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = "select c.RollNo,c.StudentName,c.Department,p.feetype,p.amount from studentheader c INNER JOIN studentdetails p on p.Rollno=c.Rollno where c.Rollno=" + TextBox1.Text + ""; DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; da.Fill(ds); con.Close(); ReportDocument CrystalReport = new ReportDocument(); string reportPath = Server.MapPath("CrystalReport.rpt"); CrystalReport.Load(reportPath); CrystalReport.SetDataSource(ds); CrystalReportViewer1.ReportSource = CrystalReport; CrystalReportViewer1.DataBind(); } }
Use the stringbulder to build the string and put debug point to test wheather ur string is formed is the correct one. for e.g Dim sbScript as new System.Text.Stringbuilder sbScript.append("Select eName,eSalary from Emp ") sbScript.append("where eid=") //Use the single quote after = sign if eid is string sbScript.append(TextBox1.Text) cmd.CommandText = sbScript.ToString() Hope this trick will be helpful to you...