我有一个WPF控制台应用程序,用C#和VS 2019编写。
我有一些水晶报告,工作没有任何问题。
现在突然:
- 如果我在调试模式下运行,一切都很好
- 如果我在我的电脑(我开发的电脑(上运行,一切都很好
- 当我部署到用户计算机时,报表会提取我用于创建报表的默认数据,但不会提取我在以下代码中加载的数据:
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
using (SqlDataAdapter adp = new SqlDataAdapter(cmd))
{
adp.Fill(ds, "Ledger");
report.SetDataSource(ds.Tables["Ledger"]);
}
}
正如我所说,在我自己的系统上,该程序正确地从SQL Server加载新数据。
但在另一台计算机上,它使用默认值。
同一个程序加载另一个Crystal Report(在同一个CS文件中(,该程序运行良好。
- 我已经尝试删除整个程序并重新复制它
- 我清除了
%AppData%
中的文件夹
我不知所措。
有什么建议吗?
当您调用crystal report时,需要从cs文件传递sqldetails/credentials,因此它将连接那个(称为运行时/动态分配数据库(,否则它将连接您在设计时配置的内容。
第二个选项需要一次,当运气不好的时候,在水晶报表中打开报表,只需从要运行的位置的顶部菜单验证数据库即可。
即使有参数,也可以从c#代码中传递,比如companyid或employeeid等。
public void loadReport()
{
rd.Load(@"C:UsersJeff EnadDesktopTEST1Cebu Hallmark Hotel Management SystemCebu Hallmark Hotel Management SystemcryReport.rpt");
SqlConnection con = new SqlConnection(@"Data Source=.SQLEXPRESS;Initial Catalog=dbCebuHallmark;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("GetAllReport", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new System.Data.DataSet();
da.Fill(ds, "REPORT");
rd.SetDataSource(ds);
rd.SetParameterValue("UserPrinted", user); //This is the parameter
crystalReportViewer1.ReportSource = rd;
crystalReportViewer1.Refresh();
}
参考这一个c#将数据库和参数传递给crystal report,crystal report询问数据库参数登录c#
或者只是在谷歌中搜索";c#水晶报表集数据库和参数";