<div> <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" Height="1039px" Width="901px" /> </div> using System.Data.SqlClient; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.ReportSource; using CrystalDecisions.Shared; private ReportDocument rpt; protected void Page_Load(object sender, EventArgs e) { ConfigureCrystalReports(); string connection = @"DATA SOURCE=JOSE-PC\SQLEXPRESS;DATABASE=MedicalDB;Integrated Security=True;"; using (SqlConnection sqlConnection = new SqlConnection(connection)) { string query = "SELECT * FROM [MedicalDB].[dbo].[CrystalReport]"; SqlCommand sqlCommand = new SqlCommand(query, sqlConnection); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(); sqlDataAdapter.SelectCommand = sqlCommand; DataSet ds = new DataSet(); sqlDataAdapter.Fill(ds); // ds.Tables[0].Rows[0]["Photo"] = (byte[])System.IO.File.ReadAllBytes(Server.MapPath("Penguins.jpg")); rpt.SetDataSource( ds.Tables[0]); CrystalReportViewer1.ReportSource = rpt; CrystalReportViewer1.RefreshReport(); } } private void ConfigureCrystalReports() { rpt = new ReportDocument(); string reportPath = Server.MapPath("CrystalReport.rpt"); rpt.Load(reportPath); ConnectionInfo connectionInfo = new ConnectionInfo(); connectionInfo.DatabaseName = "MedicalDB"; connectionInfo.IntegratedSecurity = true; //connectionInfo.UserID = ""; //connectionInfo.Password = "user123"; SetDBLogonForReport(connectionInfo, rpt); } private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument) { Tables tables = reportDocument.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables) { TableLogOnInfo tableLogonInfo = table.LogOnInfo; tableLogonInfo.ConnectionInfo = connectionInfo; table.ApplyLogOnInfo(tableLogonInfo); } } byte[] imgdata = System.IO.File.ReadAllBytes(HttpContext.Current.Server.MapPath(path)); create dataset and add fields to CrystalReport.rpt
Wednesday, September 4, 2013
Crystal Report bind from source code
Subscribe to:
Posts (Atom)