Hi all,
i am doing a project on a crystal report in c#.net and i am having some of these problems:
1>crystal report viewer is not showing the correct data.
2>Is it possible to show only one report at a time. bcoz on exporting the report, multiple files are being exported.
thanks,
Loading
Vijay YadavPosted Feb 1, 2011, 6:53 AM
public void View_Report(string Query, string CRReportName)
{
string reppath = "";
conViewReprot.con.Open();
cmd = new SqlCommand(Query, conViewReprot.con);
dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
dr.Close();
CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
string path = Application.StartupPath.ToString();
//Report folder path where crystal report resides.
string substring = path.Substring(path.IndexOf("\\") - 2, path.IndexOf("bin") - 1);
if (CRReportName == "CrystalReport1")
{
reppath = substring + "\\Reports\\" + CRReportName + ".rpt";
}
else if (CRReportName == "CrystalReport2")
{
reppath = substring + "\\Reports\\" + CRReportName + ".rpt";
}
else if (CRReportName == "CrystalReport3")
{
reppath = substring + "\\Reports\\" + CRReportName + ".rpt";
}
if (!System.IO.File.Exists(reppath))
{
MessageBox.Show("File Does not exist");
}
else
{
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
rd.Load(reppath);
crConnectionInfo.ServerName ="servername" ;
crConnectionInfo.DatabaseName = "dbname";
crConnectionInfo.UserID = "username";
crConnectionInfo.Password = "Password";
rd.SetDataSource(dt);
CrTables = rd.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
crystalReportViewer1.Refresh();
crystalReportViewer1.ReportSource = rd;
}
}
check it..
Vijay YadavPosted Feb 1, 2011, 6:46 AM
Ruchi RPosted Feb 1, 2011, 6:39 AM
thanks for ur response but it's not making any change in my reports. Anyways can u tell me how to show one report at a time in report viewer as my reportviewer is showing all the reports having same clientname.
thanks
Vijay YadavPosted Feb 1, 2011, 2:00 AM
public void ShowReport()
{
string sSql = "";
sSql ="select * from table ";
conn.connection.Open();
SqlDataReader dr = new SqlDataReader(sSql, conn.connection);
DataTable dt = new DataTable();
dt.Load(dr);
dr.Close();
rpt = new ReportDocument();
rpt.Load(Application.StartupPath + \\CrystalReport1.rpt);
rpt.SetDatabaseLogon("uname", "pword");
rpt.SetDataSource(dt);
crystalReportViewer1.Refresh();
crystalReportViewer1.ReportSource = rpt;
Just check it out..
}
Regards,
Vijay
Ruchi RPosted Feb 1, 2011, 1:51 AM
I am lil confused in it. Can you send me a sample code to display data in crystal report using datareader.
thanks
Vijay YadavPosted Feb 1, 2011, 1:00 AM
Just check it with Datareader (i.e. Connection architecture) cuz with connectionless arcchitecture i had also faced the same problem and in connectionless archi. there is no need to open and close the connection.
Regards,
Vijay
Ruchi RPosted Feb 1, 2011, 12:38 AM
The code for displaying data in crystal report is as follows:
public void displaycrystalrpt(string billid)
{
string sSql = "";
sSql ="select * from table ";
conn.connection.Open();
SqlDataAdapter da = new SqlDataAdapter(sSql, conn.connection);
DataSet ds = new DataSet();
da.Fill(ds, "table");
rpt = new ReportDocument();
string s = Application.StartupPath;
rpt.Load(Application.StartupPath + \\CrystalReport1.rpt);
crystalReportViewer1.ReportSource = rpt;
rpt.SetDatabaseLogon("uname", "pword");
rpt.SetDataSource(ds.Tables[0]);
conn.connection.Close();
}
Vijay YadavPosted Jan 31, 2011, 7:25 AM
1) What data it is showing?, If you provide the code then i would be able to suggest you.
2) And yes it is possible to show data only one report at a time.
Thanks,
Vijay