FastReport报表 不保存连接信息时使用多表数据源(代码)

今天做的报表涉及到一个报表里使用3个数据表,如何将这三个表的数据映射到fastreport中呢,看下面代码。对应的要在fastreport中将表改成这个名字,数据库连接信息就可以不用保存到报表中了。

            btnExportBargain.Enabled = false;

            int paperId = Convert.ToInt32(ucDataGridView1.Rows[ucDataGridView1.CurrentRow.Index].Cells[0].Value.ToString());

            string conStr = BaseSystemInfo.ConnectionString;
            try
            {
                SqlConnection con = new SqlConnection(conStr);
                con.Open();
                SqlCommand sqlcmd = new SqlCommand();
                sqlcmd.Connection = con;
                sqlcmd.CommandText = "select * from [VW_报表打印] where Id=" + paperId+"; select * from VW_报表打印_详细记录 where 询价单id=" + paperId + ";  select * from VW_报表打印_详细记录 where 询价单id=" + paperId + " and 是否采用=1";;
;
                SqlDataAdapter sda = new SqlDataAdapter(sqlcmd);
                sda.TableMappings.Add("Table", "Table");
                sda.TableMappings.Add("Table1", "T2");
                sda.TableMappings.Add("Table2", "T3");
                ds1 = new DataSet();
                sda.Fill(ds1);

                con.Close();
                sda.Dispose();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.StackTrace);
            }

            try
            {
                FastReport.Report report = new FastReport.Report();                
                string filename = @"D:\12.合同商定记录.frx";
                report.Load(filename);
                report.RegisterData(ds1);

                report.GetDataSource("Table").Enabled = true;
                report.GetDataSource("T2").Enabled = true;
                report.GetDataSource("T3").Enabled = true;
                report.Show();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }

            btnExportBargain.Enabled = true;


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小飞鱼通达二开

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值