|
Imports System.Data.SqlClient
Public Class ctrlConnection
Public Event DBChanged(ByVal db As String)
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
ComboboxSetTextBoxWithHistory(ComboBoxServer, ComboBoxUserId)
End Sub
Private Sub MBD(ByVal s As String)
Throw New Exception("The " & s & " must be defined!")
End Sub
Private Sub MBD(ByVal t As TextBoxBase, ByVal s As String)
If t.Text = "" Then
MBD(s)
End If
End Sub
Private Sub MBD(ByVal t As ComboBox, ByVal s As String)
If t.Text = "" Then
MBD(s)
End If
End Sub
Private Sub ValidateSUP()
MBD(ComboBoxServer, "server")
MBD(ComboBoxUserId, "user id")
MBD(TextBoxPassword, "password")
End Sub
Public ReadOnly Property ConnectionString As String
Get
ValidateSUP()
MBD(ComboBoxDatabases, "database")
Return GetConnectionString(ComboBoxServer.Text, ComboBoxUserId.Text, TextBoxPassword.Text, ComboBoxDatabases.Text)
End Get
End Property
Public Sub LoadDatabases()
ValidateSUP()
Dim cn As New SqlConnection
cn.ConnectionString = _
GetConnectionString(ComboBoxServer.Text, ComboBoxUserId.Text, TextBoxPassword.Text, "master")
Using cn
Dim cmd As New SqlCommand("SELECT name FROM sys.databases ORDER BY name", cn)
RemoveHandler ComboBoxDatabases.SelectedIndexChanged, AddressOf ComboBoxDatabases_SelectedIndexChanged
ComboBoxDatabases.DisplayMember = "name"
ComboBoxDatabases.ValueMember = "name"
ComboBoxDatabases.DataSource = GetDataset(cmd).Tables(0)
AddHandler ComboBoxDatabases.SelectedIndexChanged, AddressOf ComboBoxDatabases_SelectedIndexChanged
End Using
RaiseEvent DBChanged(ComboBoxDatabases.SelectedValue)
End Sub
Private Sub ButtonGetDatabases_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonGetDatabases.Click
Try
LoadDatabases()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub ComboBoxDatabases_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxDatabases.SelectedIndexChanged
RaiseEvent DBChanged(ComboBoxDatabases.SelectedValue)
End Sub
Private Sub TextBoxPassword_Enter(sender As System.Object, e As System.EventArgs) Handles TextBoxPassword.Enter
TextBoxPassword.SelectAll()
End Sub
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.