You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C# WinForm中DataGrid生成Stimulsoft报表报错:Option not supported(direct)

Stimulsoft报表生成错误:"Option not supported. Parameter name: direct" 原因分析

问题场景

在C# WinForm项目中,尝试将DataGrid数据传入Stimulsoft变量生成报表时,触发如下错误:

System.ArgumentException: 'Option not supported. Parameter name: direct' in stimul soft

相关代码:

string report_path = app.projectDir + @"\bin\Debug\Reports\Report_InputStore.mrt";

StiReport report = new StiReport();
report.ScriptLanguage = StiReportLanguageType.CSharp;
report.Dictionary.Databases.Clear();
report.Load(report_path);
var dataTable = new DataTable();
dataTable.Columns.Add("ShipNum");
dataTable.Columns.Add("Ptitle");
dataTable.Columns.Add("code_product");
dataTable.Columns.Add("attrValue");
dataTable.Columns.Add("company_name");
dataTable.Columns.Add("saveDate");
dataTable.Columns.Add("Pcount");
dataTable.Columns.Add("countAttr");
dataTable.Columns.Add("Psize");
dataTable.Columns.Add("PsizeAttr");
dataTable.Columns.Add("introduction");
foreach (DataGridViewRow row in DGVprintOutput2.Rows)
{
  dataTable.Rows.Add(row.Cells["ShipNum"], row.Cells["Ptitle"], row.Cells["code_product"], row.Cells["attrValue"], row.Cells["company_name"],
             row.Cells["saveDate"], row.Cells["Pcount"], row.Cells["countAttr"], row.Cells["Psize"], row.Cells["PsizeAttr"], row.Cells["introduction"]);
}
StiVariable dateVar = new StiVariable("DateDay", "todayDate", typeof(string), thisdate, false);
report.Dictionary.Variables.Add(dateVar);
report.RegData("DS-inputStore", dataTable);
report.Render(false);
report.Show();

错误原因

  • 数据传入类型错误:循环向DataTable添加行时,直接传入DataGridViewCell对象而非单元格的Value属性。Stimulsoft在解析数据时无法识别单元格对象类型,引发内部参数"direct"的不支持异常。
  • 报表模板与数据源不匹配:如果.mrt模板中预设的数据源名称、字段类型或字段数量,与代码中注册的DS-inputStore数据表不一致,会导致Stimulsoft数据映射时触发参数解析错误。
  • 变量添加时机冲突:加载报表模板后添加变量,若模板中已存在同名变量或相关脚本逻辑,可能引发参数冲突,导致"direct"参数异常。

内容的提问来源于stack exchange,提问作者hassan razeghi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 00:40:03