我創建了一個Windows窗體應用程序,該應用程序應該將新記錄添加到數據庫中。現在,它會成功添加它,並且可以使用新數據...但是,當我關閉應用程序並重新啓動它時,應用程序的行爲就好像沒有任何變化。數據庫文件不更新
數據庫是在SQL Server中創建的,應用程序使用它生成的.mdf
文件。
這裏是方法:
private void btnUnos_Click(object sender, EventArgs e)
{
//create an instance of the row to be inserted
PIScarinaDataSet.OsobaRow novaOsoba;
novaOsoba = pIScarinaDataSet.Osoba.NewOsobaRow();
//fill the attributes
novaOsoba.Ime = txtImeOsobe.Text;
novaOsoba.Drzavnost = dobijDrzavu();
novaOsoba.Predstavlja = dobijPredstavnika();
//insert into the database
this.Validate();
this.pIScarinaDataSet.Osoba.Rows.Add(novaOsoba);
this.osobaTableAdapter1.Update(this.pIScarinaDataSet.Osoba);
this.osobaBindingSource1.EndEdit();
}
.Save()?......... –
where.osobaBindingSource1.BeginEdit()? – Edper
另一個需要注意的是,由於您使用的是由SQL Server創建的.MDF,因此您需要確保Visual Studio中的文件的「Copy to Output Directory」屬性設置爲「Copy if newer」。 (或者,如果要手動將其置於正確的目錄中,請不要複製)。也就是說,如果實際上保存了數據,這就是問題所在。 –