on 05-19-2014 2:13 AM
My program is modified from VB.NET. Now I struck with Crystal Report that Crystal Report Viewer didn't show Report Document.
Printing code is composed of two forms. One assign parameters and objects need. Other is Crystal Report Viewer form, CrystalReportForm. Last one run report by parameter from the first.
When run this code that it didn't found any error but the problem is no report show on Crystal Report Viewer on second form. It just blank Crystal Report Viewer. There arm't any message response.
Here is my code.
// report caller form.
private void Print()
{
CrystalReportForm rptForm = new CrystalReportForm();
string[] strtbl;
strtbl = new string[1];
string[] strqry;
strqry = new string[1];
// prepare var
string myqry;
string myrpt;
// Pass The Table That you used in the crystal Report
strtbl[0] = "r_receipts";
// Pass the Query
myqry = "SELECT * FROM r_receipts";
myrpt = "rptReceipts.rpt";
strqry[0] = myqry;
//Pass For Mdi True
rptForm.MdiParent = this.ParentForm;
rptForm.ViewReport(myrpt, strtbl, strqry, "");
//Parameter Value It is Optional
rptForm.Show();
}
// Crytal Report Viewer form.
public void ViewReport(string ReportName , string[] TableName, string[] QueryString , string Parameter = "")
{
//Me.MdiParent = mainpage;
if (TableName.Length != QueryString.Length )
{
MessageBox.Show("Passed Variable Are Not Correct", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
CrystalDecisions.Windows.Forms.CrystalReportViewer crv = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
crv.ActiveViewIndex = 0;
crv.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
crv.ToolPanelView = CrystalDecisions.Windows.Forms.ToolPanelViewType.None;
crv.Dock = System.Windows.Forms.DockStyle.Fill;
crv.Location = new System.Drawing.Point(0, 0);
crv.Name = "CrystalReportViewer";
MySqlDataAdapter at =new MySqlDataAdapter();
DataSet ds = new DataSet();
for (int i = 0; i < TableName.Length; i++)
{
at = GetDataAdeptor(QueryString[i]);
at.Fill(ds, TableName[i]);
}
string rptPath = "";
rptPath = Application.StartupPath + "\\" + ReportName;
rpt.Load(rptPath);
rpt.SetDataSource(ds);
if (Parameter != "")
rpt.SetParameterValue(0, Parameter);
crv.ReportSource = rpt;
crv.Refresh();
//CrystalReportViewer.DataBind();
//Me.Panel1.Controls.Add(CrystalReportViewer);
Panel panel1 = new Panel();
panel1.Controls.Add(crv);
}
What happens when you export the report from viewer, does the exported pdf show any data?
as you are using dataset, this could also be an issue with DS.
Could you print the data from DS to a datagrid and see if the DS actually returns the data.
- Bhushan
Senior Engineer
SAP Active Global Support
Follow us on Twitter
Got Enhancement ideas? Try the SAP Idea Place
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bhushan,
It's not yet fixed. My dataset (ds) can't bine to DataGridView as
DataGridView1.DataSource = ds
But it could do like this
DataGridView1.DataSource = ds.Tables[0];
When I bine to Crystal Report Viewer setdatasource
CrystalReportViewer1.setdatasource = ds.Tables[0];
It still not work, anyway you suggest let me in the right way. I very confuse the thing I fix to bine to DataGridView
Thank,
Chaiwat
Try,
CrReportDocument.Setdatasource = ds.Tables[0];
CrystalReportViewer1.ReportSource = CrReportDocument;
See if this helps.
Thanks,
Bhushan
Hi
I already fixed it.
Thanks
Chaiwat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.