如何解决“数据库登录失败”错误在使用C#和Sql Server数据库发送到一个注释的打印Crystal Reports中 [英] How Do I Solve The Error Of "Database Log On Failed " In Printing Crystal Reports Using C# And Sql Server Database Sending To One Note
本文介绍了如何解决“数据库登录失败”错误在使用C#和Sql Server数据库发送到一个注释的打印Crystal Reports中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Connection.openconnection();
for (int c = 0; c < dataGridView1.Rows.Count - 1; c++)
{
SqlDataAdapter da = new SqlDataAdapter("select * from student_details,institution_details where current_class='" + this.dataGridView1.Rows[c].Cells[0].Value + "'", Connection.con);
DataSet ds = new DataSet();
da.Fill(ds, "classlist");
ReportDocument bkng = new ReportDocument();
bkng.Load(Application.StartupPath + "\\Classlist.rpt");
bkng.SetDataSource(ds.Tables["classlist"]);
PrinterSettings print = new PrinterSettings();
//pass parameters
//pass year
string strParameter1 = "";
strParameter1 = Convert .ToString (this.dataGridView1.Rows[c].Cells[0].Value);
bkng.SetParameterValue("Class", strParameter1);
bkng.PrintOptions.PrinterName = print.PrinterName;
//break point is at this line
bkng.PrintToPrinter(1, false, 0, 0);
}
Connection.closeconnection
推荐答案
aspx页面:
< cr:crystalreportviewer id =CrystalReportViewer1runat =serverxmlns:cr =#unknown>
AutoDataBind =trueDisplayGroupTree =False
EnableDatabaseLogonPrompt =FalseEnableParameterPrompt =False/>
.cs页面:
ReportDocument report = new ReportDocument();
report.Load(Application.StartupPath + \\Classlist.rpt)//报告名称report.SetParameterValue(0,abc); //提供参数值
report.SetDatabaseLogon(用户名,密码,服务器,数据库);
CrystalReportViewer1.ReportSource = report;
aspx page:
<cr:crystalreportviewer id="CrystalReportViewer1" runat="server" xmlns:cr="#unknown">
AutoDataBind="true" DisplayGroupTree="False"
EnableDatabaseLogonPrompt="False" EnableParameterPrompt="False" />
.cs page:
ReportDocument report = new ReportDocument();
report.Load(Application.StartupPath + "\\Classlist.rpt") //report name report.SetParameterValue(0, "abc"); // provide parameter value
report.SetDatabaseLogon(username, password,server,database);
CrystalReportViewer1.ReportSource = report;
这篇关于如何解决“数据库登录失败”错误在使用C#和Sql Server数据库发送到一个注释的打印Crystal Reports中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文