您好,连接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)
复制代码
|