c# - 无法在 Visual Studio 的 Crystal Report 中加载数据库信息

标签 c# visual-studio crystal-reports

我在使用 VS2013 的 Crystal Reports 时遇到问题。我有一个使用 CR 在 VS2010 中开发的 Windows 应用程序。

当我尝试在 VS 2013 中运行它时,出现以下异常:

Failed to load database information.
Error in File BillReport {E3FDAF36-9149-4F03-BCB6-EE66639AFFFB}.rpt:
Failed to load database information.
   at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e)
   at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSourceInternal(Object val, Type type)
   at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSource(DataSet dataSet)
   at Stock_Maintanance.PrintBillReport.PrintBillReport_Load(Object sender, EventArgs e) in e:\perforce\DudhatTechnologies\Users\jay vadiya\Stock Maintanance\Release 0.1\Stock Maintanance\PrintBillReport.cs:line 86
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
   at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
   at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.Form.CreateHandle()
   at System.Windows.Forms.Control.get_Handle()
   at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Control.Show()
   at Stock_Maintanance.PrintBill.btPrint_Click(Object sender, EventArgs e) in e:\perforce\DudhatTechnologies\Users\jay vadiya\Stock Maintanance\Release 0.1\Stock Maintanance\PrintBill.cs:line 717
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at Stock_Maintanance.Program.Main() in e:\perforce\DudhatTechnologies\Users\jay vadiya\Stock Maintanance\Release 0.1\Stock Maintanance\Program.cs:line 20

以下是我从 OLEDB 连接填充的 XML 数据集中加载 Crystal 报表的代码

string sqlstr = "";
sqlstr = "select * from billMaster where billid =  " + billId + " and merchantName = '" + merchantName + "' ";
// DataSet ds = m1.selectData(sqlstr);

cmd = new OleDbCommand(sqlstr, m1.ccon);
if (m1.ccon.State == ConnectionState.Closed) {
    m1.ccon.Open();
}
OleDbDataAdapter da = new OleDbDataAdapter(sqlstr, m1.ccon);

BillPrint bp = new BillPrint();

// dr = cmd.ExecuteReader();
da.Fill(bp.billMaster);
sqlstr = "select srNo from billInfo where billId=" + billId + " order by srNo";
DataSet dsTemp = m1.selectData(sqlstr);
sqlstr = "select (srNo+1-" + dsTemp.Tables[0].Rows[0].ItemArray[0].ToString() + ") as srNo,billId,itemType,itemName,length,width,thickness,squareMeter,billRate,Qty,subTotal from billInfo where billId=" + billId;
OleDbDataAdapter da1 = new OleDbDataAdapter(sqlstr, m1.ccon);
// dr = cmd.ExecuteReader();
da1.Fill(bp.billInfo);

string path = "";
path = Application.StartupPath + "\\reports\\BillReport.rpt";

/* if (RateVisible == 1)
{
    path = Application.StartupPath + "\\reports\\BillReport.rpt";
}
else if (RateVisible == 2)
{
    path = Application.StartupPath + "\\reports\\BillReportWithoutRate.rpt";
}*/
//  MessageBox.Show(path);

ReportDocument rd = new ReportDocument();
rd.Load(path);
rd.SetDataSource(bp);
crv.ReportSource = rd;
crv.RefreshReport();

最佳答案

添加 <startup> <configuration>下的代码app.config 中的元素

<startup useLegacyV2RuntimeActivationPolicy="true"></startup>

关于c# - 无法在 Visual Studio 的 Crystal Report 中加载数据库信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23902850/

相关文章:

c# - 是否存在一种类型的集合或关联数组,其中键也是和/或值的一部分?

c# - 由于 PreviewMouseLeftButtonDown,Datagrid 内的按钮未被触发

c# - 单元测试功能

visual-studio - Visual Studio 2005错误: An error occurred generating a bootstrapper: Invalid syntax

c# - 在 Visual Studio 2010 中将项目添加到项目

crystal-reports - 将子报表值传递给主报表

date - 当前日期减一个月 Crystal 报告

c# - 为模板动态创建通用类型

c# - 具有数据库文件相对路径的连接字符串

mysql - 如何在VB.NET中连接 Crystal 报表和MySQL