SHARE
TWEET

Untitled

a guest Mar 21st, 2017 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System
  2. Imports System.Data
  3. Imports System.Data.OleDb
  4. Imports System.Configuration
  5. Module MoDatabase
  6.     Public ConnectionString As String = _
  7.      "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & ConfigurationSettings.AppSettings.Item("uid") _
  8.                     & ";Password=" & ConfigurationSettings.AppSettings.Item("pwd") _
  9.                     & ";Initial Catalog=" & ConfigurationSettings.AppSettings.Item("db") _
  10.                     & ";Data Source='" & ConfigurationSettings.AppSettings.Item("server") & "'"
  11.  
  12.     Public Function getDataset(ByVal cmd As String) As DataSet
  13.  
  14.         Dim connection As OleDbConnection = Nothing
  15.  
  16.         Dim command As OleDbCommand = Nothing
  17.  
  18.         Dim sqlda As OleDbDataAdapter = Nothing
  19.  
  20.         Dim res As New DataSet
  21.         Try
  22.  
  23.             connection = New OleDbConnection(ConnectionString)
  24.  
  25.             command = New OleDbCommand(cmd, connection)
  26.  
  27.             command.CommandType = CommandType.Text
  28.  
  29.             sqlda = New OleDbDataAdapter(command)
  30.  
  31.             sqlda.Fill(res)
  32.  
  33.         Catch ex As Exception
  34.  
  35.             MessageBox.Show(ex.Message, "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error)
  36.         End Try
  37.  
  38.         Return res
  39.     End Function
  40.  
  41.  
  42.     Public Function ExecuteNonQuery(ByVal cmd As String) As Integer
  43.  
  44.         Dim connection As OleDbConnection = Nothing
  45.  
  46.         Dim transaction As OleDbTransaction = Nothing
  47.  
  48.         Dim command As OleDbCommand = Nothing
  49.         Dim res As Integer = -1
  50.         Try
  51.  
  52.             connection = New OleDbConnection(ConnectionString)
  53.  
  54.             command = New OleDbCommand(cmd, connection)
  55.  
  56.             command.CommandType = CommandType.Text
  57.  
  58.             connection.Open()
  59.  
  60.             transaction = connection.BeginTransaction()
  61.             command.Transaction = transaction
  62.  
  63.             res = command.ExecuteNonQuery()
  64.  
  65.             transaction.Commit()
  66.  
  67.         Catch ex As Exception
  68.  
  69.             If Not (transaction Is Nothing) Then
  70.                 transaction.Rollback()
  71.             End If
  72.             MessageBox.Show(ex.Message, "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error)
  73.         End Try
  74.  
  75.         Return res
  76.     End Function
  77. End Module
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top