找回密码
 立即注册

QQ登录

只需一步,快速开始

xieshangjie

注册会员

11

主题

15

帖子

68

积分

注册会员

积分
68
xieshangjie
注册会员   /  发表于:2016-7-20 23:04  /   查看:3955  /  回复:2
页面报表如何连接PostgreSQL数据库  后台语言是vb.net

2 个回复

倒序浏览
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2016-7-22 15:11:09
推荐
您好,因为之前PostgreSQL数据库连接的问题较少,给您做了一个Demo,供您了解下:
首先注意需要安装odbc驱动


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

评分

参与人数 2满意度 +10 收起 理由
xieshangjie + 5 很给力!
SunDream° + 5 很给力!

查看全部评分

回复 使用道具 举报
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2016-7-21 10:25:45
沙发
您好,连接PostgreSQL
1. 首先需要安装PostgreSQL 的ODBC 驱动程序。
2. 在后台代码中编写连接字符串
  1.   
  2. 'create an empty page report
  3. Dim def As New PageReport
  4. 'load the report layout
  5. def.Load(New System.IO.FileInfo(Application.StartupPath + "\RuntimeBinding.rdlx"))
  6. 'create and setup the data source
  7. Dim myDataSource As New GrapeCity.ActiveReports.PageReportModel.DataSource
  8. myDataSource.Name = "Example Data Source"
  9. myDataSource.ConnectionProperties.DataProvider = "ODBC"
  10. myDataSource.ConnectionProperties.ConnectString = "User ID=postgres;Password=admin;Server=192.168.0.226;Port=5432;Database=MonitorDB"
  11. 'setup the dataset
  12. Dim myDataSet As New GrapeCity.ActiveReports.PageReportModel.DataSet()
  13. Dim myQuery As New GrapeCity.ActiveReports.PageReportModel.Query()
  14. myDataSet.Name = "Example Data Set"
  15. myQuery.DataSourceName = "Example Data Source"
  16. myQuery.CommandType = GrapeCity.ActiveReports.PageReportModel.QueryCommandType.TableDirect
  17. myQuery.CommandText = GrapeCity.ActiveReports.Expressions.ExpressionInfo.FromString("Product")
  18. myDataSet.Query = myQuery
  19. ' add fields
  20. Dim _field As New GrapeCity.ActiveReports.PageReportModel.Field("ProductID", "ProductID", Nothing)
  21. myDataSet.Fields.Add(_field)
  22. _field = New GrapeCity.ActiveReports.PageReportModel.Field("InStock", "InStock", Nothing)
  23. myDataSet.Fields.Add(_field)
  24. _field = New GrapeCity.ActiveReports.PageReportModel.Field("Price", "Price", Nothing)
  25. myDataSet.Fields.Add(_field)
  26. 'bind the data source and the dataset to the report
  27. def.Report.DataSources.Add(myDataSource)
  28. def.Report.DataSets.Add(myDataSet)
复制代码


回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部