求助,请教各位大神一段代码的问题,求帮助

jcxpy910 2016-02-05 11:41:45
代码如下:
private void aaa_Load(object sender, System.EventArgs e)
{

//产生专业下拉列表
SqlConnection cn = new SqlConnection("Data Source=WIN7U-20151010U;uid=sa;pwd=gsa4tb;Initial Catalog=xsxxdb");
cn.Open();
this.label3.Text = Form1.strLogName;
SqlCommand cmd = cn.CreateCommand();
cmd.CommandText = "select rolename from userinfo where name ='" + label3.Text.ToString() + "'";
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
string temp_role = reader.GetString(0);

this.label5.Text = temp_role;
if (label5.Text == "系统管理员")
{
comboBox1.Text = "门诊部";
}
else if (label5.Text == "操作员")
{
comboBox1.Text = "急诊部";
}

// cn.Close();
}
这段代码的功能是要combobox1中显示出指定的值,但是运行过后combobox中为空,什么都没有,有没有大神能告诉我这是为什吗。。。求帮助啊,真心的
...全文
126 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
正怒月神 2016-02-06
  • 打赏
  • 举报
回复
comboBox1.item.add 增加下拉列表的选项。而不是他的text
jcxpy910 2016-02-06
  • 打赏
  • 举报
回复
那应该怎么设置 @weixin_33936651
Justin-Liu 2016-02-06
  • 打赏
  • 举报
回复
把内容作为ComboBox的ListItem添加进去
weixin_33936651 2016-02-05
  • 打赏
  • 举报
回复
你combobox属性是什么droplist不能直接设置text的

110,561

社区成员

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

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

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