Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <connectionStrings>
- <add name="PostgreConnectionStringPCMRead"
- connectionString="Server=xxx.xxx.xxx.xxx;Port=5432;User
- Id=the_user;Password=the_password;Database=example;
- CommandTimeout=600;Timeout=30;ConnectionLifeTime=30;
- Pooling=False;"/>
- </connectionStrings>
- Public Class dlNpgSQL
- Dim _sqlCommand As NpgsqlCommand
- Dim _sqlDataAdapter As NpgsqlDataAdapter
- Dim _dataset As DataSet
- Public Sub New()
- _sqlConnection = New NpgsqlConnection(ConfigurationManager.
- ConnectionStrings("connstring").ConnectionString)
- End Sub
- Public Function GetDataSet(ByVal strQuery As String) As DataSet
- _dataset = New DataSet
- _sqlDataAdapter = New NpgsqlDataAdapter(strQuery, OpenConnection)
- _sqlDataAdapter.Fill(_dataset)
- End Function
- Public Function GetDataSet(ByVal strQuery As String) As DataSet
- _dataset = New DataSet
- If _sqlConnection.State = ConnectionState.Closed Then
- _sqlConnection.Open()
- End If
- End Function
- Public Sub CloseConnection()
- If _sqlConnection.State = ConnectionState.Open Then
- _sqlConnection.Close()
- End If
- End Function
- End Class
- Dim ds As DataSet
- Dim objDBRead As New dlNpgSQL("connstring")
- tmpSQL = "SELECT * FROM table1"
- ds = objDBRead.GetDataSet(tmpSQL)
- If (objDBRead IsNot Nothing) Then
- objDBRead.CloseConnection()
- End If
Add Comment
Please, Sign In to add comment