健康一贴灵,专注医药行业管理信息化

锐浪报表通过连接字符串和SQL与程序对接(上篇为DataTable转换)

锐浪报表另一种实现,即直接在程序中传数据库连接字符串和SQL(可能会有安全隐患)

连接字符串中要使用oledb方式,(如:oracle要在连接字符串前加:"Provider=OraOLEDB.Oracle;" ,并将Persist Security Info=False;)

1、在表单的初始事件中加入初始化事件和自定义函数 ;

首先要定义几个全局变量

        string sql = "";
        string taskId="0", taskNo, carNo, driverName, superCargoName, Taskdate;
        DataTable dt,dtDetail;
        //定义Grid++Report报表主对象
        GridppReport Report = new GridppReport();

主要代码示例


public FrmDeliverPrint() { InitializeComponent(); Report.Initialize += new _IGridppReportEvents_InitializeEventHandler(ReportInitialize); } //附:ReportInitialize void ReportInitialize() { if (dataGridView1.Rows.Count < 0) return; int i = dataGridView1.CurrentCell.RowIndex; if (i < 0) return; taskNo = dataGridView1.Rows[i].Cells["TASK_BILL_NO"].Value.ToString(); carNo = dataGridView1.Rows[i].Cells["car_number"].Value.ToString(); driverName = dataGridView1.Rows[i].Cells["driver_name"].Value.ToString(); Taskdate = dataGridView1.Rows[i].Cells["create_time"].Value.ToString(); superCargoName = dataGridView1.Rows[i].Cells["SUPERCARGO_NAME"].Value.ToString(); taskId = dataGridView1.Rows[i].Cells["task_id"].Value.ToString(); Report.LoadFromFile("Report\\pcd.grf"); Report.ParameterByName("task_no").AsString = taskNo;//主报表传参 Report.ParameterByName("car_no").AsString = carNo;//主报表传参 Report.ParameterByName("driver_name").AsString = driverName;//主报表传参 Report.ParameterByName("supercargo").AsString = superCargoName;//主报表传参 Report.ParameterByName("bill_date").AsString = Taskdate;//主报表传参 Report.DetailGrid.Recordset.ConnectionString = "Provider=OraOLEDB.Oracle;" + CommFunc.GetConnString();

2、然后打印按钮事件就是一行代码

            Report.PrintPreview(true);

 

posted @ 2025-07-17 10:13  一贴灵  阅读(38)  评论(0)    收藏  举报
学以致用,效率第一