C#中使用FastReport控件报错,已具有相同键条目
程序员文章站
2022-06-26 16:14:36
...
近来工作中用到C#,还用到了FastReport.Net,过程中出现一个错误,
以下是C#代码片段,
try
{
//生成wf表
String sqlString = "select * from TEMP_WEIF where sfzmhm=:sfzmhm";
DataTable dt = OracleHelper.ExecuteDataTable(sqlString, new OracleParameter(":sfzmhm", this.flow.sfzmhm));
DataTable table = new DataTable();
table.TableName = "Table1";
DataColumn dc;
dc = new DataColumn("nf", System.Type.GetType("System.String"));
table.Columns.Add(dc);
dc = new DataColumn("0f", System.Type.GetType("System.String"));
table.Columns.Add(dc);
dc = new DataColumn("1f", System.Type.GetType("System.String"));
table.Columns.Add(dc);
dc = new DataColumn("2f", System.Type.GetType("System.String"));
table.Columns.Add(dc);
dc = new DataColumn("3f", System.Type.GetType("System.String"));
table.Columns.Add(dc);
dc = new DataColumn("6f", System.Type.GetType("System.String"));
table.Columns.Add(dc);
dc = new DataColumn("12f", System.Type.GetType("System.String"));
table.Columns.Add(dc);
dc = new DataColumn("xj", System.Type.GetType("System.String"));
table.Columns.Add(dc);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr;
dr = table.NewRow();
dr["nf"] = dt.Rows[i]["WFSJ"].ToString();
dr["0f"] = dt.Rows[i]["LINGFEN"].ToString();
dr["1f"] = dt.Rows[i]["YIFEN"].ToString();
dr["2f"] = dt.Rows[i]["ERFEN"].ToString();
dr["3f"] = dt.Rows[i]["SANFEN"].ToString();
dr["6f"] = dt.Rows[i]["LIUFEN"].ToString();
dr["12f"] = dt.Rows[i]["SHIERFEN"].ToString();
dr["xj"] = dt.Rows[i]["XIAOJI"].ToString();
wfjq = wfjq + int.Parse(dt.Rows[i]["XIAOJI"].ToString());
table.Rows.Add(dr);
}
}
DataSet ds = new DataSet();
ds.Tables.Add(table);
freport.RegisterData(ds, "Table1");
freport.SetParameterValue("wfjq", wfjq);
freport.SetParameterValue("sgjq", wfjq);
freport.SetParameterValue("mfjc", wfjq);
}
catch (Exception ex)
{
WsgzmExceptionWindow excep = new WsgzmExceptionWindow();
excep.exmsg.Text = "数据库连接异常3,停止服务!";
excep.Show();
this.Close();
return;
}
try
{
//生成mf表
String sqlString = "select * from DRV_POINT where sfzmhm=:sfzmhm";
DataTable dt3 = OracleHelper.ExecuteDataTable(sqlString, new OracleParameter(":sfzmhm", this.flow.sfzmhm));
DataTable table3 = new DataTable();
table3.TableName = "Table3";
DataColumn dc3;
dc3 = new DataColumn("qfrq", System.Type.GetType("System.String"));
table3.Columns.Add(dc3);
dc3 = new DataColumn("jfnd", System.Type.GetType("System.String"));
table3.Columns.Add(dc3);
dc3 = new DataColumn("qffz", System.Type.GetType("System.String"));
table3.Columns.Add(dc3);
dc3 = new DataColumn("wqffz", System.Type.GetType("System.String"));
table3.Columns.Add(dc3);
if (dt3.Rows.Count > 0)
{
for (int i = 0; i < dt3.Rows.Count; i++)
{
DataRow dr3;
dr3 = table3.NewRow();
dr3["qfrq"] = dt3.Rows[i]["QFRQ"].ToString();
dr3["jfnd"] = dt3.Rows[i]["JFND"].ToString();
dr3["qffz"] = dt3.Rows[i]["QFFZ"].ToString();
dr3["wqffz"] = dt3.Rows[i]["WQFFZ"].ToString();
mfjc = mfjc + 1;
table3.Rows.Add(dr3);
}
}
DataSet ds3 = new DataSet();
ds3.Tables.Add(table3);
freport.RegisterData(ds3, "Table3");
freport.SetParameterValue("mfjc", mfjc);
}
catch (Exception ex)
{
WsgzmExceptionWindow excep = new WsgzmExceptionWindow();
excep.exmsg.Text = "数据库连接异常5,停止服务!";
excep.Show();
this.Close();
return;
}
freport.Show();
以下是fastreport中代码段,
private void Table1_ManualBuild(object sender, EventArgs e)
{
// 获取DataSet中表名为Table1的数据源
DataSourceBase data1 = Report.GetDataSource("Table1");
data1.ForceLoadData=true;
data1.Init(); // 初始化
jtwfqk.PrintRow(0); // 控件Table1打印第0行
jtwfqk.PrintColumns(); // 每打印一行,都要调用 PrintColumn或PrintColumns
while(data1.HasMoreRows) // 打印重复循环的行
{
jtwfqk.PrintRow(1);
jtwfqk.PrintColumns();
data1.Next(); // 读取下一行
}
}
private void Table3_ManualBuild(object sender, EventArgs e)
{
DataSourceBase data1 = Report.GetDataSource("Table3");
// 获取DataSet中表名为Table3的数据源
data1.ForceLoadData=true;
data1.Init(); // 初始化
mfjlqk.PrintRow(0); // 控件Table1打印第0行
mfjlqk.PrintColumns(); // 每打印一行,都要调用 PrintColumn或PrintColumns
while(data1.HasMoreRows) // 打印重复循环的行
{
mfjlqk.PrintRow(1);
mfjlqk.PrintColumns();
data1.Next(); // 读取下一行
}
}
如果我控件中第二个表的ManualBuild中不调用Table3_ManualBuild就不会报错,望大神指点!
------------------------------------------------------------------------------------------------------------------手动分割
经同事指点,在FastReport控件里,表分开写,放到Child里,就不会报错(奇怪的是我自己想到过这种方法,但是放到Child不显示数据,同事告诉我以后就出数据了,这就是命啊!!)
上一篇: Linux正则表达式
下一篇: 如何基于自定义变量绘制图表