Hi!
Can I get some help in this codes. From my button when I call a print preview I didnt receive a fully print preview page asually. The crystalReportViewer still there on my form showing all datas. But it'snot what I want. I would like after cliking on my preview's button to see a fully crystal report print preview page. Later I can print it out if I want.
private void button2_Click(object sender, EventArgs e)
{
ReportDocument
"c:/search//search//CrystalReport1.rpt");
cryRpt.Load(
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
cryRpt = new ReportDocument();}
//Thanx
Pravin GhadgePosted Dec 13, 2011, 12:01 PM
Israel MfwambaPosted Dec 13, 2011, 10:30 AM
Every think is right, right, right. But I have this message "the connectionString property has not been initailized". I did follow my path is sound fine. I dont know why still giving me this message and stark here ---> con.Open().
private{
frmReport
report.View_Reports("c://search//search//CrystalReport2.rpt", "Select * from ficha_inscr");//Pass query
report.ShowDialog();
}
public{
{con = new SqlConnection();
SqlConnection
con.Open();
void View_Reports( string ReportName,string Querry)con.ConnectionString =
string reppath = "";
SqlDataAdapter da1 = new SqlDataAdapter(Querry, con);
DataSet ds = new DataSet();
da1.Fill(ds);
CrystalDecisions.CrystalReports.Engine.
ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();reppath =
rd.Load(reppath);
rd.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = rd;
crystalReportViewer1.ShowCloseButton = true;
con.Close();
}
"Data source=.\\SQLEXPRESS;AttachDbFilename=C:\\Programas\\Microsoft SQL Server\\MSSQL\\Data\\Luna_Escola.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; report = new frmReport();//Create object of Report Formvoid button1_Click(object sender, EventArgs e)frmReport report = new frmReport();//Create object of Report Form
Pravin GhadgePosted Dec 13, 2011, 4:28 AM
Replace ur code
1)
private void button2_Click(object sender, EventArgs e)
{
frmReport report = new frmReport();//Create object of Report Form
report.View_Reports("crptMyReport.rpt","Select * from tblname");//Pass query
report.showdialog();
}
2)
public void View_Reports( string ReportName,string Querry)
{
SqlConnection con = new SqlConnection();
con .ConnectionString = "Data source=localhost;uid=sa;pwd=***;database=MyDbName;";
con.Open();
string reppath = "";
SqlDataAdapter da1 = new SqlDataAdapter(Querry, con);
DataSet ds = new DataSet();
da1.Fill(ds);
CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
reppath =Application.StartupPath + "\\" + ReportName;
rd.Load(reppath);
rd.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = rd;
crystalReportViewer1.ShowCloseButton = true;
}
con
Israel MfwambaPosted Dec 12, 2011, 1:34 PM
'Search.frmReport' does not contain a definition 'ViewReport' and no extension method 'ViewReport' accepting a first argument of type 'Searc.frmReport' could be found...
the second is:
the name 'con' does not exist in the current context
the name 'rd' does not exist in the current context
Pravin GhadgePosted Dec 12, 2011, 12:32 PM
Israel MfwambaPosted Dec 12, 2011, 12:29 PM
Thanx. but doesnt work. Maybe I'm wrong. See what I did:
Where I underline in blue. Its where is the problem.
private void button2_Click(object sender, EventArgs e)
{
frmReport report = new frmReport();//Create object of Report Form
report.ViewReport("crptMyReport.rpt","Select * from tblname");//Pass query
report.showdialog();
}
public void View_Reports( string ReportName,string Querry)
{
string reppath = "";
SqlDataAdapter da1 = new SqlDataAdapter(Querry, con);
DataSet ds = new DataSet();
da1.Fill(ds);
rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
reppath =Application.StartupPath + "\\" + ReportName;
rd.Load(reppath);
rd.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = rd;
crystalReportViewer1.ShowCloseButton = true;
}
Thanx;
Pravin GhadgePosted Dec 12, 2011, 10:17 AM
1)Add new Form Say 'frmReport'
2)add Crystalreportviewer on this form.
3)if u have form say 'Form1' which has Preview Button.
After u click on this button
private void button2_Click(object sender, EventArgs e)
{
frmReport report = new frmReport();//Create object of Report Form
report.ViewReport("crptMyReport.rpt","Select * from tblname");//Pass query
report.showdialog();
}
U can use foll code:
public void View_Reports( string ReportName,string Querry)
{
string reppath = "";
SqlDataAdapter da1 = new SqlDataAdapter(Querry, con);
DataSet ds = new DataSet();
da1.Fill(ds);
rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
reppath =Application.StartupPath + "\\" + ReportName;
rd.Load(reppath);
rd.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = rd;
crystalReportViewer1.ShowCloseButton = true;
}
This may help u