C#如何调用Fastreport
我用的是C#语言..用fastreport做一个报表,需要根据后台选中的数据库表中的ID来显示具体的信息现在我如何把后台根据条件查询到的数据集传给fastreport文件...
我用的是C# 语言..用fastreport 做一个报表,需要根据后台选中的数据库表中的ID来显示具体的信息
现在我如何 把后台根据条件查询到的数据集传给
fastreport文件进行绑定.
我做的是B/S结构的 要连接到fastreport这个工具 展开
现在我如何 把后台根据条件查询到的数据集传给
fastreport文件进行绑定.
我做的是B/S结构的 要连接到fastreport这个工具 展开
2个回答
展开全部
引用:FastReport.dll,FastReport.Bars.dll,FastReport.Editor.dll
设计好**.frx 文件
代码:
DataSet FDataSet = new DataSet();
DataTable table = new DataTable();
table.TableName = "Items";
FDataSet.Tables.Add(table);
table.Columns.Add("id", typeof(int));
table.Columns.Add("aaa", typeof(string));
table.Rows.Add(0,"ab");
table.Rows.Add(1,"abc");
FastReport.Report report1 = new FastReport.Report();
try
{
// load the existing report
report1.Load("***.frx");
// register the dataset
report1.RegisterData(FDataSet);
report1.GetDataSource("Items").Enabled = true;
// run the report
report1.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
// free resources used by report
report1.Dispose();
}
设计好**.frx 文件
代码:
DataSet FDataSet = new DataSet();
DataTable table = new DataTable();
table.TableName = "Items";
FDataSet.Tables.Add(table);
table.Columns.Add("id", typeof(int));
table.Columns.Add("aaa", typeof(string));
table.Rows.Add(0,"ab");
table.Rows.Add(1,"abc");
FastReport.Report report1 = new FastReport.Report();
try
{
// load the existing report
report1.Load("***.frx");
// register the dataset
report1.RegisterData(FDataSet);
report1.GetDataSource("Items").Enabled = true;
// run the report
report1.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
// free resources used by report
report1.Dispose();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你给的分有点少呀,给你了。
<body MS_POSITIONING="GridLayout">
<OBJECT id=report1
codeBase="<%=HTTPStr%>/common/ocx/ReportActiveFormProj1.ocx#version=2,0,0,0"
height=830 hspace=0 width="100%" align=center vspace=0
classid=clsid:B9BE2CBF-747A-49E5-AD52-9D983D9536E8 VIEWASTEXT>
<PARAM NAME="Visible" VALUE="0">
<PARAM NAME="AutoScroll" VALUE="0">
<PARAM NAME="AutoSize" VALUE="0">
<PARAM NAME="AxBorderStyle" VALUE="1">
<PARAM NAME="Caption" VALUE="ReportActiveFormX">
<PARAM NAME="Color" VALUE="2147483663">
<PARAM NAME="Font" VALUE="宋体">
<PARAM NAME="KeyPreview" VALUE="0">
<PARAM NAME="PixelsPerInch" VALUE="96">
<PARAM NAME="PrintScale" VALUE="1">
<PARAM NAME="Scaled" VALUE="-1">
<PARAM NAME="DropTarget" VALUE="0">
<PARAM NAME="HelpFile" VALUE="">
<PARAM NAME="DoubleBuffered" VALUE="0">
<PARAM NAME="Enabled" VALUE="-1">
<PARAM NAME="Cursor" VALUE="0">
<PARAM NAME="HelpType" VALUE="0">
<PARAM NAME="HelpKeyword" VALUE="">
<PARAM NAME="ColNum" VALUE="0">
<PARAM NAME="ExportFileName" VALUE="">
</OBJECT>
<script>
report1.SetfrfFilePath('<%= modelPath %>')
<%=mm%>
report1.ShowReport();
</script>
<form id="Form1" method="post" runat="server">
<FONT face="宋体"></FONT>
</form>
</body>
这是打印界面代码
---------------------------------------------------------------------
private void Page_Load(object sender, System.EventArgs e)
{
string modelPath_host = Request.ServerVariables["LOCAL_ADDR"];
HTTPStr = "http://" + modelPath_host;
modelPath = "http://"+modelPath_host+"/common/ocx/rpfile/query_errorpinyin_report.txt";//指到模板的网站路径
Brjl.BcMis.Common.Query.ErrorPy query = (Brjl.BcMis.Common.Query.ErrorPy)Session["Query_Error_Pinyin"];//获取查询参数
using(DataSet ds = new Brjl.BcMis.Bussiness.Queries.ErrorPy().GetErrorCode(query)//查询后的数据集
{
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
int num = i+1;
mm=mm+"report1.AddMultiData(\"data1\",\""+num.ToString()+"\");\n";
mm=mm+"report1.AddMultiData(\"data2\",\""+ds.Tables[0].Rows[i]["jc"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data3\",\""+ds.Tables[0].Rows[i]["neeaid"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data4\",\""+ds.Tables[0].Rows[i]["cname"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data5\",\""+ds.Tables[0].Rows[i]["pinyin"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data6\",\""+ds.Tables[0].Rows[i]["aa"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data7\",\""+ds.Tables[0].Rows[i]["name"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data8\",\""+ds.Tables[0].Rows[i]["phone"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data9\",\""+ds.Tables[0].Rows[i]["mobile"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data10\",\""+ds.Tables[0].Rows[i]["email"].ToString().Replace("\r\n"," ")+"\");\n";
mm=mm+"report1.AddMultiData(\"data11\",\""+ds.Tables[0].Rows[i]["address"].ToString().Replace("\r\n"," ")+"\");\n";
}
mm="report1.BindMultiDataTofrBind('data1,data2,data3,data4,data5,data6,data7,data8,data9,data10,data11','mm');\n"+mm;//循环后赋给mm 字符串,这些data 就是你模板上的控件id
}
}
后台代码----------------------------------------------------------------
应该还有简单的方法,一条sql语句就行了,在找找
-----------------------------------------------------------------------
上班是以前的版本,要是用最新的就是只要sql语句
<script language="javascript">
{
report1.SetReportFile("<%=modelPath%>");
report1.SetQuerySql("ADOQuery1","<%=sql%>");
report1.ShowReport();
}
</script>
不懂在加分,我给你解释。
<body MS_POSITIONING="GridLayout">
<OBJECT id=report1
codeBase="<%=HTTPStr%>/common/ocx/ReportActiveFormProj1.ocx#version=2,0,0,0"
height=830 hspace=0 width="100%" align=center vspace=0
classid=clsid:B9BE2CBF-747A-49E5-AD52-9D983D9536E8 VIEWASTEXT>
<PARAM NAME="Visible" VALUE="0">
<PARAM NAME="AutoScroll" VALUE="0">
<PARAM NAME="AutoSize" VALUE="0">
<PARAM NAME="AxBorderStyle" VALUE="1">
<PARAM NAME="Caption" VALUE="ReportActiveFormX">
<PARAM NAME="Color" VALUE="2147483663">
<PARAM NAME="Font" VALUE="宋体">
<PARAM NAME="KeyPreview" VALUE="0">
<PARAM NAME="PixelsPerInch" VALUE="96">
<PARAM NAME="PrintScale" VALUE="1">
<PARAM NAME="Scaled" VALUE="-1">
<PARAM NAME="DropTarget" VALUE="0">
<PARAM NAME="HelpFile" VALUE="">
<PARAM NAME="DoubleBuffered" VALUE="0">
<PARAM NAME="Enabled" VALUE="-1">
<PARAM NAME="Cursor" VALUE="0">
<PARAM NAME="HelpType" VALUE="0">
<PARAM NAME="HelpKeyword" VALUE="">
<PARAM NAME="ColNum" VALUE="0">
<PARAM NAME="ExportFileName" VALUE="">
</OBJECT>
<script>
report1.SetfrfFilePath('<%= modelPath %>')
<%=mm%>
report1.ShowReport();
</script>
<form id="Form1" method="post" runat="server">
<FONT face="宋体"></FONT>
</form>
</body>
这是打印界面代码
---------------------------------------------------------------------
private void Page_Load(object sender, System.EventArgs e)
{
string modelPath_host = Request.ServerVariables["LOCAL_ADDR"];
HTTPStr = "http://" + modelPath_host;
modelPath = "http://"+modelPath_host+"/common/ocx/rpfile/query_errorpinyin_report.txt";//指到模板的网站路径
Brjl.BcMis.Common.Query.ErrorPy query = (Brjl.BcMis.Common.Query.ErrorPy)Session["Query_Error_Pinyin"];//获取查询参数
using(DataSet ds = new Brjl.BcMis.Bussiness.Queries.ErrorPy().GetErrorCode(query)//查询后的数据集
{
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
int num = i+1;
mm=mm+"report1.AddMultiData(\"data1\",\""+num.ToString()+"\");\n";
mm=mm+"report1.AddMultiData(\"data2\",\""+ds.Tables[0].Rows[i]["jc"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data3\",\""+ds.Tables[0].Rows[i]["neeaid"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data4\",\""+ds.Tables[0].Rows[i]["cname"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data5\",\""+ds.Tables[0].Rows[i]["pinyin"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data6\",\""+ds.Tables[0].Rows[i]["aa"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data7\",\""+ds.Tables[0].Rows[i]["name"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data8\",\""+ds.Tables[0].Rows[i]["phone"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data9\",\""+ds.Tables[0].Rows[i]["mobile"]+"\");\n";
mm=mm+"report1.AddMultiData(\"data10\",\""+ds.Tables[0].Rows[i]["email"].ToString().Replace("\r\n"," ")+"\");\n";
mm=mm+"report1.AddMultiData(\"data11\",\""+ds.Tables[0].Rows[i]["address"].ToString().Replace("\r\n"," ")+"\");\n";
}
mm="report1.BindMultiDataTofrBind('data1,data2,data3,data4,data5,data6,data7,data8,data9,data10,data11','mm');\n"+mm;//循环后赋给mm 字符串,这些data 就是你模板上的控件id
}
}
后台代码----------------------------------------------------------------
应该还有简单的方法,一条sql语句就行了,在找找
-----------------------------------------------------------------------
上班是以前的版本,要是用最新的就是只要sql语句
<script language="javascript">
{
report1.SetReportFile("<%=modelPath%>");
report1.SetQuerySql("ADOQuery1","<%=sql%>");
report1.ShowReport();
}
</script>
不懂在加分,我给你解释。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询