ComboBox与数据库绑定后同步问题
一个按纽 负责删除 ComboBox(手动连接数据库) 选中的内容按完删除后, ComboBox 选中的内容没有被即时删除(数据库中已经删除)
等再一次打开软件后, ComboBox 刚刚选中的内容才被删除
按纽的代码:
private void delete_Click(object sender, EventArgs e)
{
string str1 = "Data Source=.;Initial Catalog=prince;Integrated Security=True";
try
{
SqlConnection conn = new SqlConnection(str1);
conn.Open();
string sql = "delete from Song where Address=" +"'"+comboBox1.Text.ToString()+"'";
SqlCommand cmd = new SqlCommand(sql, conn);
int i = cmd.ExecuteNonQuery();
conn.Close();
if (i > 0)
{
MessageBox.Show("You Had Deleted" + comboBox1.Text.ToString());
}
else
{
MessageBox.Show("Delete fail");
}
}
catch (SystemException ex)
{
MessageBox.Show("Error:" + ex.Message);
}
}
强调一下 ComboBox手动连接数据库