我正试图使基于项目选择抛出组合框的SQL语句。我想有默认项目选择作为ID,但现在它返回NULL。我做错了什么?
private void Win_Shown(object sender, EventArgs e)
{
myBox.SelectedValue = "ID";
myBox.SelectedText = "ID";
myBox.SelectedItem = "ID";
myBox.Items.Add("ID");
myBox.Items.Add("Name");
myBox.Items.Add("Surname");
myBox.Items.Add("Mobile");
}
Then in for SQL语句
MySQL.DisplayAndSearch("SELECT * FROM Data WHERE " + this.myBox.SelectedItem.ToString() + " LIKE '%" + txt_Search.Text + "%'", dataGridView1);
谢谢你的帮助:)
在插入前选择条目:
private void Win_Shown(object sender, EventArgs e)
{
// first, add the items
myBox.Items.Add("ID");
myBox.Items.Add("Name");
myBox.Items.Add("Surname");
myBox.Items.Add("Mobile");
// now select it
myBox.SelectedItem = "ID";
}
你试过了吗?
private void Win_Shown(object sender, EventArgs e)
{
myBox.Items.Add("ID");
myBox.Items.Add("Name");
myBox.Items.Add("Surname");
myBox.Items.Add("Mobile");
// now select it
myBox.SelectedIndex = myBox.FindString("Mobile");//id..etc
}