如何填充comboBox控件,急!!!

aa_1736 2007-04-02 09:56:39
//获取指定数据库服务器的数据库列表
public ArrayList GetDbList(string strServerName, string strUserName, string strPwd)
{
string ServerName = strServerName;
string UserName = strUserName;
string Password = strPwd;

ArrayList alDbs = new ArrayList();
SQLDMO.Application sqlApp = new SQLDMO.ApplicationClass();
SQLDMO.SQLServer svr = new SQLDMO.SQLServerClass();
try
{
svr.Connect(ServerName, UserName, Password);
foreach (SQLDMO.Database db in svr.Databases)
{
if (db.Name != null)
alDbs.Add(db.Name);
}
}
catch (Exception e)
{
throw (new Exception("连接数据库出错:" + e.Message));
}
finally
{
svr.DisConnect();
sqlApp.Quit();
}
return alDbs;
}

上面这个函数已经实现了获取数据库列表,如何将这些获取的数据库全部显示在comboBox控件里啊?
...全文
219 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
哈哈007哈 2007-04-02
  • 打赏
  • 举报
回复
同意楼上
winer2006 2007-04-02
  • 打赏
  • 举报
回复
this.cmbServer.Items.Clear();

foreach (SQLDMO.Database db in svr.Databases)
{
if (db.Name != null)
alDbs.Add(db.Name);
this.cmbServer.Items.Add(db.Name);
}
if (this.cmbServer.Items.Count > 0) this.cmbServer.SelectedIndex = 0;
王集鹄 2007-04-02
  • 打赏
  • 举报
回复
comboBox1.Items.Add("Zswang 路过");
kenra 2007-04-02
  • 打赏
  • 举报
回复
d

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧