数据库访问和组合框

时间:2011-12-11 02:09:31

标签: c# winforms visual-studio-2010

我有一个数据库访问权限表“学生”和3列“ID”,“电子邮件”和“名称”。 在组合框中,我在列“name”处插入了与数据库的连接。从combobox中选择名称后,可能会显示一个消息框,其中包含来自数据库的id和电子邮件,对应于所选名称?

1 个答案:

答案 0 :(得分:0)

使用ComboBox的Click事件。您可以在方法中使用,如 在ComboBox选择:

//this method you will get after you double click the ComboBox in the Form       
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (comboBox1.SelectedIndex > 0)
    {
        comboBox1.Click += new EventHandler(this.IWantToDisplayMessageBox);
    }
}

public void IWantToDisplayMessageBox(object sender, EventArgs e)
{
    MessageBox.Show("student ID and email");
}

在哪里,您可能希望在ComboBox的第0个索引处使用“select”字符串。现在,您唯一需要做的就是调用您创建的数据库访问者,并提供在MessageBox中选择的该学生的ID和电子邮件

相关问题