xieshangjie 发表于 2016-7-20 23:04:40

页面报表如何在后台代码中绑定数据源

页面报表如何连接PostgreSQL数据库后台语言是vb.net

Lenka.Guo 发表于 2016-7-22 15:11:09

您好,因为之前PostgreSQL数据库连接的问题较少,给您做了一个Demo,供您了解下:
首先注意需要安装odbc驱动


Lenka.Guo 发表于 2016-7-21 10:25:45

您好,连接PostgreSQL
1. 首先需要安装PostgreSQL 的ODBC 驱动程序。
2. 在后台代码中编写连接字符串

'create an empty page report
Dim def As New PageReport
'load the report layout
def.Load(New System.IO.FileInfo(Application.StartupPath + "\RuntimeBinding.rdlx"))
'create and setup the data source
Dim myDataSource As New GrapeCity.ActiveReports.PageReportModel.DataSource
myDataSource.Name = "Example Data Source"
myDataSource.ConnectionProperties.DataProvider = "ODBC"
myDataSource.ConnectionProperties.ConnectString = "User ID=postgres;Password=admin;Server=192.168.0.226;Port=5432;Database=MonitorDB"
'setup the dataset
Dim myDataSet As New GrapeCity.ActiveReports.PageReportModel.DataSet()
Dim myQuery As New GrapeCity.ActiveReports.PageReportModel.Query()
myDataSet.Name = "Example Data Set"
myQuery.DataSourceName = "Example Data Source"
myQuery.CommandType = GrapeCity.ActiveReports.PageReportModel.QueryCommandType.TableDirect
myQuery.CommandText = GrapeCity.ActiveReports.Expressions.ExpressionInfo.FromString("Product")
myDataSet.Query = myQuery
' add fields
Dim _field As New GrapeCity.ActiveReports.PageReportModel.Field("ProductID", "ProductID", Nothing)
myDataSet.Fields.Add(_field)
_field = New GrapeCity.ActiveReports.PageReportModel.Field("InStock", "InStock", Nothing)
myDataSet.Fields.Add(_field)
_field = New GrapeCity.ActiveReports.PageReportModel.Field("Price", "Price", Nothing)
myDataSet.Fields.Add(_field)
'bind the data source and the dataset to the report
def.Report.DataSources.Add(myDataSource)
def.Report.DataSets.Add(myDataSet)

页: [1]
查看完整版本: 页面报表如何在后台代码中绑定数据源