Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Module DatabaseConnectionsModule
  2.  
  3.     Public con As New OleDb.OleDbConnection
  4.     Public Const dbProvider As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
  5.     Public dbSource As String = "Data Source = " & Application.StartupPath.Substring(0, Application.StartupPath.Length - 9) & "Access\" & "Simple.mdb"
  6.  
  7.     Public ds As New DataSet
  8.     Public da As OleDb.OleDbDataAdapter
  9.  
  10.     Public sql As String = "select * from myTable"
  11.  
  12.     Sub ConnectToDatabase(ByVal strSQL As String, ByVal strTable As String)
  13.  
  14.         'Connect to
  15.  
  16.         con.ConnectionString = dbProvider & dbSource
  17.         con.Open()
  18.  
  19.         'This takes the data from the Access table and puts it into the form
  20.        'It will show the first record in the form
  21.  
  22.         da = New OleDb.OleDbDataAdapter(strSQL, con)
  23.         da.Fill(ds, strTable)
  24.  
  25.         con.Close()
  26.  
  27.     End Sub
  28.  
  29.     Sub DisconnectFromDatabase()
  30.  
  31.         'clear the dynaset
  32.  
  33.         ds.Clear()
  34.         con.Close()
  35.  
  36.     End Sub
  37.  
  38.  
  39.  
  40.  
  41. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement