Working with ObjectDataSource in VS2005

Working with ObjectDataSource in VS2005

Postby Guest » Sat 26 Aug 2006 07:05

Version of Visual Studio .NET or another IDE : VS2005
Version of PostgreSQLDirect .NET. :2.50.18.0
Version of your PostgreSQL server : 8.1.4
Version of your operating system :Windows XP
Problem

I would like to make use of VS2005’s objectdatasource, I’m familiar with the making a connection to a MS SQL sever and returning a dataset, however I’m unsure how to make the connection to a postgre database using PostgreSQLDirect and returning a dataset. Could someone please assist me with the necessary object that I have to use and connection string in order to do this.

Here is a sample of the connection I’m making to a MS SQL server database, all I need to know is how to get PostgreSQLDirect to work with IDbConnection and return a dataset

Imports Microsoft.VisualBasic

Imports System



Public Class EntDB



Public Sub New()



End Sub



Shared Function GetDebtors() As System.Data.DataSet

Dim connectionString As String = ConfigurationManager.ConnectionStrings("dolphinmis_dbConnectionString").ConnectionString

Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)



Dim queryString As String = "SELECT ent_id, ent FROM ent"

Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand

dbCommand.CommandText = queryString

dbCommand.Connection = dbConnection



Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter

dataAdapter.SelectCommand = dbCommand

Dim dataSet As System.Data.DataSet = New System.Data.DataSet

dataAdapter.Fill(dataSet)



Return dataSet

End Function



End Class
Guest
 

Postby Alexey » Mon 28 Aug 2006 07:24

Try to use the following code:
Code: Select all
Imports Microsoft.VisualBasic
Imports System
Imports CoreLab.PostgreSql

Public Class EntDB

  Public Sub New()
  End Sub

  Shared Function GetDebtors() As System.Data.DataSet
        Dim connectionString As String = "User Id=postgres;Password=postgres;Database=testdb;Schema=test;Host=localhost"
        Dim dbConnection As System.Data.IDbConnection = New CoreLab.PostgreSql.PgSqlConnection(connectionString)
        Dim queryString As String = "SELECT ent_id, ent FROM ent"
        Dim dbCommand As System.Data.IDbCommand = New CoreLab.PostgreSql.PgSqlCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection
        Dim dataAdapter As System.Data.IDbDataAdapter = New CoreLab.PostgreSql.PgSqlDataAdapter
        dataAdapter.SelectCommand = dbCommand
        Dim dataSet As System.Data.DataSet = New System.Data.DataSet
        dataAdapter.Fill(dataSet)
        Return dataSet
  End Function

End Class
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for PostgreSQL