Advertisement
ayami123

Module for Access

Aug 19th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.58 KB | None | 0 0
  1. Imports System.Data.OleDb
  2. Module Module1
  3.     Public dbPath As String = Application.StartupPath & "\PayrollCortez.accdb"
  4.     Public connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath
  5.  
  6.  
  7.     Public Function perfromQuery(ByVal connectionsString As String, ByVal sqlCommand As String) As OleDb.OleDbDataAdapter
  8.         Dim dbConnection As OleDbConnection
  9.         Dim dbCommand As New OleDbCommand()
  10.         Dim dbDataReader As OleDb.OleDbDataAdapter = Nothing
  11.  
  12.         Try
  13.             dbConnection = New OleDbConnection(connectionsString)
  14.             dbCommand.CommandText = sqlCommand
  15.             dbCommand.Connection = dbConnection
  16.             dbConnection.Open()
  17.             dbDataReader = dbCommand.ExecuteReader
  18.             Return dbDataReader
  19.             dbConnection.Close()
  20.         Catch ex As Exception
  21.             MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  22.         End Try
  23.  
  24.         Return Nothing
  25.     End Function
  26.  
  27.  
  28.     Public Function performNonQuery(ByVal connectionString As String, ByVal sqlCommand As String) As Boolean
  29.         Dim dbConnection As OleDbConnection
  30.         Dim dbCommand As New OleDbCommand()
  31.  
  32.         Try
  33.             dbConnection = New OleDbConnection(connectionString)
  34.             dbCommand.CommandText = sqlCommand
  35.             dbCommand.Connection = dbConnection
  36.             dbCommand.Connection.Open()
  37.             dbCommand.ExecuteNonQuery()
  38.             dbConnection.Close()
  39.         Catch ex As Exception
  40.  
  41.         End Try
  42.         Return True
  43.  
  44.     End Function
  45. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement