哪位大哥给一个c#winfrom调用打印报表的列子 类似fastreport
展开全部
刚做了测试,我是参考这位大神的网页链接
private void button1_Click(object sender, EventArgs e)
{
Report rep = new Report();
SqlConnection conn = new SqlConnection(@"Data Source=.;Integrated Security=true;Initial Catalog=SD11812N_Sample;");
string filename = @"C:\Users\Administrator\Desktop\测试.frx";
try
{
string sql = "select code,name,specs,unit from goods";
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter sd = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sd.Fill(ds);
conn.Close();//关闭数据库连接
sd.Dispose();//释放资源
rep.Load(filename);//加载模版
rep.RegisterData(ds);
rep.GetDataSource(ds.Tables[0].TableName).Enabled = true;
rep.Show();//显示报表
}
catch (Exception er)
{
MessageBox.Show(er.Message);
conn.Close();
throw;
}
}
报表模版
打印预览 效果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询