如何提供水晶报告的登录详细信息 [英] how to provide login details to crystal report
本文介绍了如何提供水晶报告的登录详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
水晶报告不断询问用户名和密码。我使用SQL查询生成报告,如何在代码中提供此用户名和密码。我试过这个但没有工作。请帮助我
crystal report keeps asking for user name and password. Am using SQL query to generate the report, how do i provide this user name and password in the codes. i tried this but not working.please help me out
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
conn.ConnectionString = "Data Source=USER-PC;Initial Catalog=MUCGPROJECT;User ID=sa;Password=mike";
SqlCommand cmd = new SqlCommand(string.Format("SELECT * FROM tblCollectorsRegistration WHERE Collectorid='{0}'", this.txtCollectorid.Text), conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
conn.Close();
DataTable tbl = new DataTable();
conn.Open();
SqlDataAdapter adp = new SqlDataAdapter("SELECT Collectorid, Title, Surname, Firstname, Middlename, Gender, Dateofbirth, Nationality, Religion, Maritalstatus, Spousename, Telephone, Postaladdress, Residentialaddress, Hometownaddress from tblCollectorsRegistration WHERE Collectorid = '" + this.txtCollectorid.Text + "'", conn);
adp.Fill(tbl);
rptCollectorindividual objRpt = new rptCollectorindividual();
objRpt.Database.Tables[0].SetDataSource(tbl);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Refresh();
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtablelognoinfos = new TableLogOnInfos();
TableLogOnInfo crtablelognoinfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
cryRpt.Load("D:\\my project\\Drms\\Ghpservice\\rptCollectorindividual.rpt");
crConnectionInfo.ServerName = "USER-PC";
crConnectionInfo.DatabaseName = "MUCGPROJECT";
crConnectionInfo.UserID = "sa";
crConnectionInfo.Password = "mike";
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtablelognoinfo = CrTable.LogOnInfo;
crtablelognoinfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtablelognoinfo);
}
}
else
{
// Id already present
MessageBox.Show("The Collector ID does not Exist");
return;
}
推荐答案
您好,
您需要通过服务器凭据代码如下:
Hello,
You need to pass server credentials through code like this :
rptDoc.SetDatabaseLogon(yourDatabaseServerUsername, yourDatabaseServerPassword);
示例:
Example :
rptDoc.SetDatabaseLogon("sa", "123");
这篇关于如何提供水晶报告的登录详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文