Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports Microsoft.SqlServer.Server
- Imports System.Data.SqlClient
- Module modFunction
- 'Private Const strConnection As String = "server=dmns-2013\sqlexpress;initial catalog=informationsystem;user id=svrjrdn;password=c3m3tery;"
- Private Const strConnection As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & _
- "'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\InformationSystem.mdf';" & _
- "Integrated Security=True;Connect Timeout=30;User Instance=True"
- Public objCon As New SqlConnection(strConnection)
- Public objCmd As New SqlCommand
- Public objDr As SqlDataReader
- Public objDa As New SqlDataAdapter
- Public objDt As New DataTable
- Public objDs As DataSet
- Public Sub OpenConnection()
- Try
- With objCon
- If .State = ConnectionState.Closed Then
- .Open()
- frmMain.slblReadyError.Text = "Ready"
- End If
- End With
- Catch ex As Exception
- MsgBox(ex.Message, MsgBoxStyle.Critical, "Connection error")
- frmMain.slblReadyError.Text = "Connection error"
- Application.Exit()
- End Try
- End Sub
- Public Sub CloseConnection()
- Try
- With objCon
- If .State = ConnectionState.Open Then
- .Close()
- End If
- End With
- Catch ex As Exception
- MsgBox(ex.Message, MsgBoxStyle.Critical, "Connection error")
- Application.Exit()
- End Try
- End Sub
- Public Sub BindCombobox(ByVal qry As String, ByVal dtext As String, ByVal dvalue As String, ByVal cbo As ComboBox)
- Try
- OpenConnection()
- objDa = New SqlDataAdapter(qry, objCon)
- objDt = New DataTable
- objDa.Fill(objDt)
- If objDt.Rows.Count > 0 Then
- With cbo
- .DataSource = objDt
- .DisplayMember = dtext
- .ValueMember = dvalue
- .SelectedIndex = 0
- End With
- End If
- Catch ex As Exception
- MsgBox(ex.Message)
- Finally
- CloseConnection()
- End Try
- End Sub
- Public Sub ClearTextbox(ByVal mFrm As Form)
- Dim txt As Control
- For Each txt In mFrm.Controls
- If TypeOf txt Is TextBox Then
- txt.Text = ""
- End If
- Next
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement