我檢查了這個主題的答案,但我仍然不知道爲什麼這不工作!請幫忙!C#Databound列表框刷新
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」不會刷新,並且不會顯示添加的項目,儘管它們在數據庫中!
你真的明白你寫的代碼嗎?這看起來像[貨物崇拜編程](http://en.wikipedia.org/wiki/Cargo_cult_programming)... – 2012-03-21 21:45:12
我已經嘗試了很多不同的編碼方式......現在對我來說都是一絲不苟。你能在「執行查詢」之後提供幫助嗎? – user799920 2012-03-21 21:48:23