Click here to Skip to main content
16,018,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Here i am developing one desktop application by using c#. In that project am using crystalreport with ms access as database. But at the time of running when i am opening report it is asking user name and password, I havnt given any password for database,dynamically i have set servername and database, but it not working. The same code is working in another report and its opening very well. Here is my code

OleDbCommand cmdGet = new OleDbCommand("SELECT * FROM supp_due where suppid= '" + TextBox2.Text.Trim() + "'", MyCon.Con);
          
            OleDbDataAdapter adGet = new OleDbDataAdapter(cmdGet);
            DataSet dsGet = new DataSet();
            adGet.Fill(dsGet, "supp_due");
 SupplierRpt2 _SupRpt = new SupplierRpt2();
            _SupRpt.DataSourceConnections[0].SetConnection(Application.StartupPath.ToString(), "Shop.mdb","","");
            _SupRpt.SetDataSource(dsGet);
            
            CrystalReportViewer1.ReportSource = _SupRpt;
            
            CrystalReportViewer1.Refresh();


So please help me

Thanks
Sujith
Posted
Updated 19-Jan-12 23:05pm
v2
Comments
Jαved 20-Jan-12 5:06am    
Added pre tag.

1 solution

Try Below code only change the class and method inside
C#
DataTable dt = new DataTable();
         dt = Module.fillgridProject();
            try
            {
                if (dt.Rows.Count > 0)
                {
                    ReportDocument rptdoc = new ReportDocument();
                    rptdoc.Load(Server.MapPath("~\\Reports\\ModuleReport.rpt"));
                    rptdoc.SetDataSource(dt);
                    //crv.ReportSource = rptdoc;
                    //crv.DataBind();
                    ExportOptions exportOpts1 = rptdoc.ExportOptions;
                    rptdoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                    rptdoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                    rptdoc.ExportOptions.DestinationOptions = new DiskFileDestinationOptions();
                    ((DiskFileDestinationOptions)rptdoc.ExportOptions.DestinationOptions).DiskFileName = Server.MapPath("ProjectReport.pdf");
                    rptdoc.Export();
                    rptdoc.Close();
                    rptdoc.Dispose();
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.ContentType = "application/pdf";
                    Response.AppendHeader("Content-Disposition", "attachment; filename=ProjectReport.pdf");
                    Response.WriteFile("ProjectReport.pdf");
                    Response.Flush();
                    Response.Close();
                   System.IO.File.Delete(Server.MapPath("ProjectReport.pdf"));
                }
                else
                {
                    Messagebox1.Show("No Record for this Project");
                }
            }
            catch 
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Hello", "javascript:alert('No Data Present');", true);
            }
 
Share this answer
 
v2
Comments
Jαved 20-Jan-12 5:09am    
added pre tag.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900