Advertisement
calfred2808

module. database (infoSystem -jordan)

Jan 19th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.57 KB | None | 0 0
  1. Imports Microsoft.SqlServer.Server
  2. Imports System.Data.SqlClient
  3.  
  4. Module modFunction
  5.     'Private Const strConnection As String = "server=dmns-2013\sqlexpress;initial catalog=informationsystem;user id=svrjrdn;password=c3m3tery;"
  6.     Private Const strConnection As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & _
  7.                                             "'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\InformationSystem.mdf';" & _
  8.                                             "Integrated Security=True;Connect Timeout=30;User Instance=True"
  9.     Public objCon As New SqlConnection(strConnection)
  10.     Public objCmd As New SqlCommand
  11.     Public objDr As SqlDataReader
  12.     Public objDa As New SqlDataAdapter
  13.     Public objDt As New DataTable
  14.     Public objDs As DataSet
  15.  
  16.     Public Sub OpenConnection()
  17.  
  18.  
  19.  
  20.         Try
  21.             With objCon
  22.                 If .State = ConnectionState.Closed Then
  23.                     .Open()
  24.                     frmMain.slblReadyError.Text = "Ready"
  25.                 End If
  26.             End With
  27.         Catch ex As Exception
  28.             MsgBox(ex.Message, MsgBoxStyle.Critical, "Connection error")
  29.             frmMain.slblReadyError.Text = "Connection error"
  30.             Application.Exit()
  31.         End Try
  32.     End Sub
  33.  
  34.     Public Sub CloseConnection()
  35.         Try
  36.             With objCon
  37.                 If .State = ConnectionState.Open Then
  38.                     .Close()
  39.                 End If
  40.             End With
  41.         Catch ex As Exception
  42.             MsgBox(ex.Message, MsgBoxStyle.Critical, "Connection error")
  43.             Application.Exit()
  44.         End Try
  45.     End Sub
  46.  
  47.     Public Sub BindCombobox(ByVal qry As String, ByVal dtext As String, ByVal dvalue As String, ByVal cbo As ComboBox)
  48.         Try
  49.             OpenConnection()
  50.             objDa = New SqlDataAdapter(qry, objCon)
  51.             objDt = New DataTable
  52.             objDa.Fill(objDt)
  53.             If objDt.Rows.Count > 0 Then
  54.                 With cbo
  55.                     .DataSource = objDt
  56.                     .DisplayMember = dtext
  57.                     .ValueMember = dvalue
  58.                     .SelectedIndex = 0
  59.                 End With
  60.             End If
  61.         Catch ex As Exception
  62.             MsgBox(ex.Message)
  63.         Finally
  64.             CloseConnection()
  65.         End Try
  66.     End Sub
  67.  
  68.     Public Sub ClearTextbox(ByVal mFrm As Form)
  69.         Dim txt As Control
  70.         For Each txt In mFrm.Controls
  71.             If TypeOf txt Is TextBox Then
  72.                 txt.Text = ""
  73.             End If
  74.         Next
  75.     End Sub
  76. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement