protected void InitDomain() { if (string.IsNullOrEmpty(Table)) { MessageBox.Show("Table is not populated for chooser", "Table is not populated for chooser", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } controller = DBBrowserController.GetInstance(); string sql = "SELECT * FROM " + Table; List <List <object> > result = controller.ExecuteSelectSQL(sql, true); if (result != null && result.Count > 0) { List <object> columns = result[0]; foreach (object obj in columns) { DataGridViewColumn column = getDataGridViewTextBoxColumn((string)obj); dataGridView1.Columns.Add(column); if (obj.Equals(Identifier)) { identifierIndex = columns.IndexOf(obj); } } for (int i = 1; i < result.Count; i++) { List <object> row = result[i]; dataGridView1.Rows.Add(row.ToArray()); } } }
public LoginForm() { try { controller = DBBrowserController.GetInstance(); InitializeComponent(); authenticationComboBox.Text = "Windows Authentication"; /*RegistryValueDataReader registryValueDataReader = new RegistryValueDataReader(); * string[] instances64Bit = registryValueDataReader.ReadRegistryValueData(Util.RegistryHive.Wow64, * Registry.LocalMachine, * @"SOFTWARE\Microsoft\Microsoft SQL Server", * "InstalledInstances"); * * string[] instances32Bit = registryValueDataReader.ReadRegistryValueData(Util.RegistryHive.Wow6432, * Registry.LocalMachine, * @"SOFTWARE\Microsoft\Microsoft SQL Server", * "InstalledInstances"); * IList<string> localInstanceNames = new List<string>(instances64Bit); * localInstanceNames = localInstanceNames.Union(instances32Bit).ToList();*/ SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance; DataTable dataTable = instance.GetDataSources(); foreach (System.Data.DataRow row in dataTable.Rows) { string serverName = ""; string instanceName = ""; foreach (System.Data.DataColumn col in dataTable.Columns) { if ("ServerName".Equals(col.ColumnName)) { serverName = row[col] == null ? null : row[col].ToString(); } else if ("InstanceName".Equals(col.ColumnName)) { instanceName = row[col] == null ? null : row[col].ToString(); } } if (!string.IsNullOrWhiteSpace(instanceName)) { serverName = serverName + "\\" + instanceName; } serverNameComboBox.Items.Add(serverName); } } catch (Exception ex) { MessageBox.Show("Error while Loading Application " + ex.Message, "Error while Loading Application", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } }