private void Form1_Load(object sender, EventArgs e) { SQLDMO.Application app = new SQLDMO.Application(); SQLDMO.NameList sqlList = app.ListAvailableSQLServers(); for (int i = 1; i < sqlList.Count; i++) { cmbServer.Items.Add(sqlList.Item(i)); } SetText(); }
private void getSqlServer() {//获取数据库服务器列表 SQLDMO.Application SQLServer = new SQLDMO.Application(); SQLDMO.NameList strServerList = SQLServer.ListAvailableSQLServers(); if (strServerList.Count > 0) { for (int i = 0; i < strServerList.Count; i++) { cbbSqlServerName.Items.Add(strServerList.Item(i + 1));//将找到的服务器添加到comboBox中显示 } } }