protected void Button3_Click(object sender, EventArgs e) { //SqlCommand cmd = null; SqlDataAdapter da = null; DataTable dt = new DataTable(); DataTable dt1 = new DataTable(); con.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM Transactions WHERE report_type = @report_type "); cmd.Connection = con; cmd.Parameters.Add("@report_type", SqlDbType.NVarChar).Value = TextBox1.Text; da = new SqlDataAdapter(cmd); dt.Clear(); da.Fill(dt); if (dt.Rows.Count > 0) { ReportDocument Report = new ReportDocument(); Report.Load(Server.MapPath("~/Report.rpt")); Report.SetDataSource(dt); TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); ConnectionInfo crConnectionInfo = new ConnectionInfo(); Tables CrTables; Report.SetDatabaseLogon("sa", "123456789", @"TRAINING-ROOM-8", "newMreport"); CrystalReportViewer1.ReportSource = Report; CrystalReportViewer1.ReportSource = Report; CrystalReportViewer1.DataBind(); CrTables = Report.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) { crtableLogoninfo = CrTable.LogOnInfo; crtableLogoninfo.ConnectionInfo = crConnectionInfo; CrTable.ApplyLogOnInfo(crtableLogoninfo); } Report.Refresh(); Report.PrintToPrinter(1, true, 1, 1); con.Close(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)