我已经检查了有关此主题的答案,但是我仍然不知道为什么这不起作用!请帮忙!
private void btnAdd_Click(object sender, EventArgs e)
{
SqlCeCommand insTitle = new SqlCeCommand("Insert into Titles(Title) values('" + txtAddTitle.Text +"')");
insTitle.Connection = dbConnection;
try
{
if (dbConnection.State == ConnectionState.Closed) { dbConnection.Open(); }
insTitle.ExecuteNonQuery();
this.hRDataSet.AcceptChanges();
this.titlesTableAdapter.Update(this.hRDataSet);
this.tableAdapterManager.UpdateAll(this.hRDataSet);
lstTitles.BeginUpdate();
lstTitles.DataSource = titlesBindingSource;
lstTitles.DisplayMember = "Title";
lstTitles.ValueMember = "Title_ID";
lstTitles.EndUpdate();
}
catch (Exception insErr)
{
MessageBox.Show(insErr.Message);
}
}
列表框“lstTitles”不会刷新,也不会显示添加的项目,尽管它们在数据库中!