日期:2014-05-19  浏览次数:20821 次

水晶报表编译时报错
下面这段代码我写在WinForm窗体的Load事件里面,编译时报错:
重载 "Load "方法未获取参数 "1 "
我在网上搜了下这个问题,CSDN上有人问过,但没有答案.我今天用到水晶报表时也碰见了,束手无策,希望大家帮我.  

try
{
  CrystalReportTest   crystalReportTest   =   new   CrystalReportTest();
  SqlConnection   conn   =   new   SqlConnection();
  DataSet   dataSet   =   new   DataSet();

  conn.ConnectionString   =   "server=(local);database=northwind;uid=sa;pwd=sa ";

  SqlDataAdapter   datOrders   =   new   SqlDataAdapter( "select   *   from   Orders ",conn);

  SqlDataAdapter   datOrdersDetails   =   new   SqlDataAdapter( "select   *   from   [Order   Details] ",conn);

  datOrders.Fill(dataSet, "OrdersTable ");
  datOrdersDetails.Fill(dataSet, "OrdersDetailsTable ");

  string   crystalReportPath;

  crystalReportPath   =   Application.StartupPath   +   "\\CrystalReportTest.rpt ";

  crystalReportTest.Load(crystalReportPath);
  crystalReportTest.SetDataSource(dataSet);

  crystalReportViewer1.ReportSource   =   crystalReportTest;
}
catch(SqlException   sqle)
{
  MessageBox.Show(   "错误   :   "   +   sqle.Message.ToString()   );
}

------解决方案--------------------
你在最前面已經實例了一個crystalReportTest,又在后面crystalReportTest.Load(crystalReportPath);做什么.
改成以下試試:
try
{
CrystalReportTest crystalReportTest = new CrystalReportTest();
SqlConnection conn = new SqlConnection();
DataSet dataSet = new DataSet();

conn.ConnectionString = "server=(local);database=northwind;uid=sa;pwd=sa ";

SqlDataAdapter datOrders = new SqlDataAdapter( "select * from Orders ",conn);

SqlDataAdapter datOrdersDetails = new SqlDataAdapter( "select * from [Order Details] ",conn);

datOrders.Fill(dataSet, "OrdersTable ");
datOrdersDetails.Fill(dataSet, "OrdersDetailsTable ");

crystalReportTest.SetDataSource(dataSet);

crystalReportViewer1.ReportSource = crystalReportTest;
}
catch(SqlException sqle)
{
MessageBox.Show( "错误 : " + sqle.Message.ToString() );
}