Guest User

Untitled

a guest
Dec 18th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. <connectionStrings>
  2. <add name="PostgreConnectionStringPCMRead"
  3. connectionString="Server=xxx.xxx.xxx.xxx;Port=5432;User
  4. Id=the_user;Password=the_password;Database=example;
  5. CommandTimeout=600;Timeout=30;ConnectionLifeTime=30;
  6. Pooling=False;"/>
  7. </connectionStrings>
  8.  
  9. Public Class dlNpgSQL
  10. Dim _sqlCommand As NpgsqlCommand
  11. Dim _sqlDataAdapter As NpgsqlDataAdapter
  12. Dim _dataset As DataSet
  13.  
  14. Public Sub New()
  15. _sqlConnection = New NpgsqlConnection(ConfigurationManager.
  16. ConnectionStrings("connstring").ConnectionString)
  17. End Sub
  18.  
  19. Public Function GetDataSet(ByVal strQuery As String) As DataSet
  20. _dataset = New DataSet
  21. _sqlDataAdapter = New NpgsqlDataAdapter(strQuery, OpenConnection)
  22. _sqlDataAdapter.Fill(_dataset)
  23. End Function
  24.  
  25. Public Function GetDataSet(ByVal strQuery As String) As DataSet
  26. _dataset = New DataSet
  27. If _sqlConnection.State = ConnectionState.Closed Then
  28. _sqlConnection.Open()
  29. End If
  30. End Function
  31.  
  32. Public Sub CloseConnection()
  33. If _sqlConnection.State = ConnectionState.Open Then
  34. _sqlConnection.Close()
  35. End If
  36. End Function
  37. End Class
  38.  
  39. Dim ds As DataSet
  40. Dim objDBRead As New dlNpgSQL("connstring")
  41. tmpSQL = "SELECT * FROM table1"
  42. ds = objDBRead.GetDataSet(tmpSQL)
  43. If (objDBRead IsNot Nothing) Then
  44. objDBRead.CloseConnection()
  45. End If
Add Comment
Please, Sign In to add comment