【发布时间】:2015-09-17 20:28:35
【问题描述】:
ComboBox 不显示数据,我以这种方式使用数据库中的数据填充组合框:
private void PartDefective(string id)
{
cmd = new SQLiteCommand("Select * FROM Part_defective where testers = '" + id + "'", DBcon);
if (DBcon.State == ConnectionState.Closed)
DBcon.Open();
myDA = new SQLiteDataAdapter(cmd);
myDataSet = new DataSet();
myDA.Fill(myDataSet, "comboBox6");
this.comboBox6.DataSource = myDataSet.Tables["comboBox6"].DefaultView;
this.comboBox6.ValueMember = "Part";
this.comboBox6.DisplayMember = "Part";
this.comboBox6.SelectedItem = "ID";
this.comboBox6.SelectedIndex = -1;
DBcon.Close();
}
并显示我使用的数据库中的数据:
private void comboBox6_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.comboBox6.SelectedValue == null)
{
testerid = "1";
}
else
{
part = this.comboBox6.SelectedText.ToString();
}
}
【问题讨论】:
-
在这一行下断点:this.comboBox6.DataSource = myDataSet.Tables["comboBox6"].DefaultView;
-
你愿意Sql注入使用参数化查询
标签: c# visual-studio combobox userform