本文介绍了水晶报告记录显示问题asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用vs2008通过Crystal Reports打印记录。 但是在显示时它会显示第一条记录中的所有记录。 但我想打印取决于查询。 但我的代码没有执行或工作。 请帮忙。 ReportDocument cryRpt = new ReportDocument(); TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); ConnectionInfo crConnectionInfo = new ConnectionInfo(); 表格CrTables; string connStr = ConfigurationManager.ConnectionStrings [ LocalSqlServer这个]的ConnectionString。 SqlConnection con = new SqlConnection(connStr); con.Open(); SqlDataAdapter da3 = new SqlDataAdapter( 从详细信息中选择*,其中slno =' + TextBox1.Text + ' ,con); DataSet ds3 = new DataSet(); da3.Fill(ds3, 详情); cryRpt.Load(HttpContext.Current.Server.MapPath( rptFlexiReceipt.rpt)); cryRpt.SetDataSource(ds3); crConnectionInfo.ServerName = 123.123.123.123; crConnectionInfo.DatabaseName = database1; crConnectionInfo.UserID = user1; crConnectionInfo.Password = password1; CrTables = cryRpt.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) { crtableLogoninfo = CrTable.LogOnInfo; crtableLogoninfo.ConnectionInfo = crConnectionInfo; CrTable.ApplyLogOnInfo(crtableLogoninfo); } CrystalReportViewer1.ReportSource = cryRpt; System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument(); int i; int rawKind = 0 ; for (i = 0 ; i < ; printDoc.PrinterSettings.PaperSizes.Count; i ++) { if (printDoc.PrinterSettings.PaperSizes [i] .PaperName == 10x6) { rawKind =( int )GetField(printDoc.PrinterSettings.PaperSizes [i], kind ); } } cryRpt.PrintOptions.PaperSize =(CrystalDecisions.Shared.PaperSize)rawKind; // cryRpt.PrintToPrinter(1,true,0,0); cryRpt.SetDataSource(ds3); CrystalReportViewer1.RefreshReport(); 请注意我要执行的查询行号9 。解决方案 ReportDocument cryRpt = new ReportDocument(); TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); ConnectionInfo crConnectionInfo = new ConnectionInfo(); 表格CrTables; string connStr = ConfigurationManager.ConnectionStrings [LocalSqlServer]。ConnectionString; SqlConnection con = new SqlConnection(connStr); con.Open(); SqlDataAdapter da3 = new SqlDataAdapter(select * from FlexiDetails where slno =''+ TextBox1.Text +'',con); DataSet ds3 = new DataSet(); da3.Fill(ds3,finalbill); cryRpt.Load(HttpContext.Current.Server.MapPath(rptFlexiReceipt.rpt)); cryRpt.SetDataSource(ds3.Tables [0]); crConnectionInfo.ServerName =208.91.198.196; crConnectionInfo.DatabaseName =sevamx7z_SEVADBES; crConnectionInfo.UserID =seva_root; crConnectionInfo.Password =seva @ 321; CrTables = cryRpt.Database.Tables; foreach(CrTables中的CrystalDecisions.CrystalReports.Engine.Table CrTable) { crtableLogoninfo = CrTable.LogOnInfo; crtableLogoninfo.ConnectionInfo = crConnectionInfo; CrTable.ApplyLogOnInfo(crtableLogoninfo); } CrystalReportViewer1.ReportSource = cryRpt; System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument(); int i; int rawKind = 0; for(i = 0; i< printDoc.PrinterSettings.PaperSizes.Count; i ++) { if(printDoc.PrinterSettings.PaperSizes [i] .PaperName ==10x6) { rawKind =(int)GetField(printDoc.PrinterSettings.PaperSizes [i],kind); } } //cryRpt.PrintOptions.PaperSize =(CrystalDecisions.Shared.PaperSize)rawKind; // cryRpt.PrintToPrinter(1,true,0,0); cryRpt.SetDataSource(ds3); CrystalReportViewer1.RefreshReport(); 注意行 cryRpt.SetDataSource(ds3.Tables [0]); I am using vs2008 to print records in through Crystal Reports.But at the time of display it is displaying all the records, from the first record.but I want to print depending on a query.but my code is not executing or working.Please help.ReportDocument cryRpt = new ReportDocument(); TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); ConnectionInfo crConnectionInfo = new ConnectionInfo(); Tables CrTables; string connStr = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString; SqlConnection con = new SqlConnection(connStr); con.Open(); SqlDataAdapter da3 = new SqlDataAdapter("select * from Details where slno='" + TextBox1.Text + "'", con); DataSet ds3 = new DataSet(); da3.Fill(ds3, "Details"); cryRpt.Load(HttpContext.Current.Server.MapPath("rptFlexiReceipt.rpt")); cryRpt.SetDataSource(ds3); crConnectionInfo.ServerName = "123.123.123.123"; crConnectionInfo.DatabaseName = "database1"; crConnectionInfo.UserID = "user1"; crConnectionInfo.Password = "password1"; CrTables = cryRpt.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) { crtableLogoninfo = CrTable.LogOnInfo; crtableLogoninfo.ConnectionInfo = crConnectionInfo; CrTable.ApplyLogOnInfo(crtableLogoninfo); } CrystalReportViewer1.ReportSource = cryRpt; System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument(); int i; int rawKind = 0; for (i = 0; i < printDoc.PrinterSettings.PaperSizes.Count; i++) { if (printDoc.PrinterSettings.PaperSizes[i].PaperName == "10x6") { rawKind = (int)GetField(printDoc.PrinterSettings.PaperSizes[i], "kind"); } } cryRpt.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)rawKind; // cryRpt.PrintToPrinter(1, true, 0, 0); cryRpt.SetDataSource(ds3); CrystalReportViewer1.RefreshReport();please notice the line no 9 the query I want to execute. 解决方案 ReportDocument cryRpt = new ReportDocument(); TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); ConnectionInfo crConnectionInfo = new ConnectionInfo(); Tables CrTables; string connStr = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString; SqlConnection con = new SqlConnection(connStr); con.Open(); SqlDataAdapter da3 = new SqlDataAdapter("select * from FlexiDetails where slno=''" + TextBox1.Text + "''", con); DataSet ds3 = new DataSet(); da3.Fill(ds3, "finalbill"); cryRpt.Load(HttpContext.Current.Server.MapPath("rptFlexiReceipt.rpt")); cryRpt.SetDataSource(ds3.Tables[0]); crConnectionInfo.ServerName = "208.91.198.196"; crConnectionInfo.DatabaseName = "sevamx7z_SEVADBES"; crConnectionInfo.UserID = "seva_root"; crConnectionInfo.Password = "seva@321"; CrTables = cryRpt.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) { crtableLogoninfo = CrTable.LogOnInfo; crtableLogoninfo.ConnectionInfo = crConnectionInfo; CrTable.ApplyLogOnInfo(crtableLogoninfo); } CrystalReportViewer1.ReportSource = cryRpt; System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument(); int i; int rawKind = 0; for (i = 0; i < printDoc.PrinterSettings.PaperSizes.Count; i++) { if (printDoc.PrinterSettings.PaperSizes[i].PaperName == "10x6") { rawKind = (int)GetField(printDoc.PrinterSettings.PaperSizes[i], "kind"); } } //cryRpt.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)rawKind; // cryRpt.PrintToPrinter(1, true, 0, 0); cryRpt.SetDataSource(ds3); CrystalReportViewer1.RefreshReport();NOTICE LINEcryRpt.SetDataSource(ds3.Tables[0]); 这篇关于水晶报告记录显示问题asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-25 03:22