的时候在bin\Debug\...文件目录下找不到报表文件,会报错。
3、代码,这里给报表附数据源,datatable和dataset都可以。
private void FormFR_Load(object sender, EventArgs e)
{
DataSet data = null;
string conStr = "Server=\'127.0.0.1\';database=demo;UID=\'sa\';PWD=\'wsn******\';";
try
{
SqlConnection con = new SqlConnection(conStr);
con.Open();
string sql = @"select Dept.DeptID,Dept.DeptName,UserInfo.UserName,UserInfo.Salary from
dbo.Dept left join dbo.UserInfo on Dept.ID=UserInfo.DeptID";
SqlCommand sqlcmd = new SqlCommand(sql, con);
SqlDataAdapter sda = new SqlDataAdapter(sqlcmd);
data = new DataSet();
sda.Fill(data);
con.Close();
sda.Dispose();
}
catch (Exception err)
{
MessageBox.Show(err.StackTrace);
}
try
{
FastReport.Report report = new FastReport.Report();
string filename = @"Reports\fr一览.frx";
report.Load(filename);
report.Preview = this.previewControl1;//让报表显示在窗体的控件中
report.RegisterData(data);
report.SetParameterValue("time", DateTime.Now.Date.ToString("yyyy-MM-dd"));//报表里的参数赋值
report.Prepare();
report.ShowPrepared();
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}