//Console.Write(s)
string constr = "Data Source=192.168.0.85Initial Catalog=CMBARCODEPersist Security Info=TrueUser ID=dbnamePassword=access"
DataOpt daa = new DataOpt()
SqlConnection conn = new SqlConnection(constr)
DataSet1 mydata = new DataSet1()
string sqlstr = "select JobNum,RequireDate,PartNum,PartDescription,RequireQty,IssuedQty, purcomment,warehousecode,pickper,sendper from material_dan where JobNum ='" + s + "'"
SqlDataAdapter myadapter = new SqlDataAdapter(sqlstr, conn)
myadapter.Fill(mydata, "material_dan")
CrystalReport3 cr = new CrystalReport3()
cr.SetDataSource(mydata)
crystalReportViewer1.ReportSource = cr
}
我做的水晶报表,给你参考下
VS2010不在像VS2008及以前版本那样支持Crystal Report了,不过SAP公司还是很给劲的,随即发布了CR for2010的免费开放版。虽然如此,但刚上手使用的朋友们可能还是很费周折。下简述使用。如果只是为了能够在VS2010中运行有报表的程序,则可以简单的将运行程序所需的dll引入项目即可。如果你的机器没有这些组件可以来这下载:点我。一般只需要引用
CrystalDecisions.CrystalReports.Engine.dll、CrystalDecisions.Shared.dll和
CrystalDecisions.Web.dll即可。下载后将其放入web/bin下,然后引用它们就可以了。 上述只适用于运行他人编写的有关报表的项目,做为开发者则还需进行其他工作。
VS2010不在支持Crystal report的设计,我们下载SAP公司的免费版(for VS2010)来设计即可(设计过程同在VS2008中没什么区别,只是环境独立了)。随后将我们设计的第一个报表文件crTeacherWorkLoad.rpt文件拷贝到项目App_Data中。
我们使用CryStalReportViewer控件来显示刚才设计好的rpt文件。VS2010IDE工具箱中不包含该控件,如果你安装了CR for VS2010则可以使用如下方法来显示该控件:
如果没有此控件则可以直接将此控件的代码放入所需的aspx页面中,然后在这个aspx页面内注册此控件。
控件代码如下所示:
[xhtml]view plaincopyprint?
1. <CR:CrystalReportViewerID="CrystalReportViewer1"runat="server"
2. AutoDataBind="true"DisplayGroupTree="false"Height="50px"Width="350px"/>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" DisplayGroupTree="false" Height="50px" Width="350px"/>注册代码放到页面头头,代码如下所示:
[xhtml]view plaincopyprint?
1. <%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral,
PublicKeyToken=692fbea5521e1304"
2. Namespace="CrystalDecisions.Web"TagPrefix="CR" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>如此以来再有了前面的三个dll的引用,就可以使用此控件来显示所需要的报表内容了。显示过程代码如下所示:
[c-sharp]view plaincopyprint?
1. //加载报表文件,设置报表源
2. ReportDocumentreportDocument = new ReportDocument()
3. reportDocument.Load(Server.MapPath("../../App_Data/crTeacherWorkLoad.rpt")) 4. reportDocument.SetDataSource(DtAllTeacherWorkLoad)//)//DtAllTeacherWorkLoad是查询
出来的DataTable,其字段同rpt文件字段相同 5. 6.
7. CrystalReportViewer1.ReportSource = reportDocument 8. //将数据库信息传递给报表 9. //定义水晶报表的数据库连接信息
10. ConnectionInfoconnectionInfo = new ConnectionInfo()
11. string aservername, bDBName, cUserId, dPwd 12. //获取服务器名、数据库名,登录名,密码
13. aservername = System.Configuration.ConfigurationManager.AppSettings["ServerName"] 14. bDBName = System.Configuration.ConfigurationManager.AppSettings["DataBase"] 15. cUserId = System.Configuration.ConfigurationManager.AppSettings["UserId"] 16. dPwd = System.Configuration.ConfigurationManager.AppSettings["PassWord"] 17. connectionInfo.DatabaseName = bDBName 18. connectionInfo.UserID = cUserId 19. connectionInfo.Password = dPwd
20. connectionInfo.ServerName = aservername 21.
22. //SetDbLoginForReport(connectionInfo) 23.
24. TableLogOnInfostableLogOnInfos = CrystalReportViewer1.LogOnInfo 25.
26. foreach (TableLogOnInfotableLogOnInfo in tableLogOnInfos) 27. { 28.
29. tableLogOnInfo.ConnectionInfo = connectionInfo 30. 31. }
[csharp]view plaincopyprint?
1. //加载报表文件,设置报表源 ReportDocument reportDocument = new ReportDocument()
[csharp]view plaincopyprint?
1. reportDocument.Load(Server.MapPath("../../App_Data/crTeacherWorkLoad.rpt"))
[csharp]view plaincopyprint?
1. reportDocument.SetDataSource(DtAllTeacherWorkLoad)//)
[csharp]view plaincopyprint?
1. //DtAllTeacherWorkLoad是查询出来的DataTable,其字段同rpt文件字段相
同 CrystalReportViewer1.ReportSource = reportDocument
[csharp]view plaincopyprint?
1. //将数据库信息传递给报表
[csharp]view plaincopyprint?
1. //定义水晶报表的数据库连接信
息 ConnectionInfo connectionInfo = new ConnectionInfo()string aservername, bDBName, cUserId, dPwd
[csharp]view plaincopyprint?
1. //获取服务器名、数据库名,登录名,密
码 aservername = System.Configuration.ConfigurationManager.AppSettings["ServerName"]
[csharp]view plaincopyprint?
1. bDBName = System.Configuration.ConfigurationManager.AppSettings["DataBase"]
[csharp]view plaincopyprint?
1. cUserId = System.Configuration.ConfigurationManager.AppSettings["UserId"]
[csharp]view plaincopyprint?
1. dPwd = System.Configuration.ConfigurationManager.AppSettings["PassWord"]
[csharp]view plaincopyprint?
1. connectionInfo.DatabaseName = bDBNameconnectionInfo.UserID = cUserId
[csharp]view plaincopyprint?
1. connectionInfo.Password = dPwdconnectionInfo.ServerName = aservername
[csharp]view plaincopyprint?
1. //SetDbLoginForReport(connectionInfo)
[csharp]view plaincopyprint?
1. TableLogOnInfos tableLogOnInfos = CrystalReportViewer1.LogOnInfo
[csharp]view plaincopyprint?
1. foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
[csharp]view plaincopyprint?
1. { tableLogOnInfo.ConnectionInfo = connectionInfo}
本文讲了三个小问题,一是如何引用所需dll显示报表文件,二是如何注册CrystalReportViewer控件,三是如何使CrystalReportViewer控件显示报表数据。至于报表文件(rpt)的设计则要学习Crystal Report 10软件的使用了!
图片 的属性里面有个 图片位置 的设定在这里面 只定你的图片路径就好 绝对 相对 都无所谓
比如 "../../../pub/common/img/" + "_logo.jpg"
什么 格式化?
就是 那个页面的 第二个tab 不就是 图片吗? 就在那里面设置
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)