How to Get SQL Servers into Combo Box in VB.NET Source Code
The below function , finds the all SQL server instants over network. All server lists are stored into 'cmbServers' Combobox.
Public Sub GetServerList(ByVal cmbServers As ComboBox)
Dim Server As String = String.Empty
Dim instance As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance
Dim table As System.Data.DataTable = instance.GetDataSources()
For Each row As System.Data.DataRow In table.Rows
Server = String.Empty
Server = row("ServerName")
If row("InstanceName").ToString.Length > 0 Then
Server = Server & "\" & row("InstanceName")
End If
cmbServers.Items.Add(Server)
Next
cmbServers.SelectedIndex = cmbServers.FindStringExact(Environment.MachineName)
End Sub
No comments:
Post a Comment