我遇到了通過使用DataAdapter回寫到Access數據庫(.accdb)的問題。向DataSet中添加一個新項目,將其寫入Access DB
目前,我有一個填充方法,用數據填充DataSet表。這段代碼目前位於我的Form_Load()中。
// TODO: This line of code loads data into the 'hCAliasDataSet.Topics' table. You can move, or remove it, as needed.
this.topicsTableAdapter.Fill(this.hCAliasDataSet.Topics);
然後,我有一個cmdAdd_Click()事件,這顯然是添加一個新行,在hCAliasDataSet內坐在Topcis表。
// Create a new row, append it to Topics table.
DataRow DR;
DR = this.hCAliasDataSet.Tables["Topics"].NewRow();
this.hCAliasDataSet.Tables["Topics"].Rows.Add(DR);
接下來,我創建了一些代碼來caputre的列值的一個輸入。
// Capture user input
sTopicName = Interaction.InputBox("Please Enter Topic Name", "Topic Name", null, 100, 100);
// Set the Topic value for the new Row
DR["Topic"] = sTopicName;
我的問題,我假設在這裏,我調用dataAdapter來更新主題表。我手動檢查數據庫,並且沒有創建任何新行?
// Commit the changes back to the hCAlias DataBase (hcalias.accdb).
this.topicsTableAdapter.Update(this.hCAliasDataSet.Topics);
編輯:我相信我需要創建一個INSERT查詢,我的TableAdapter,這會是正確的嗎?
你可以看到這個博客。 http://www.cnblogs.com/chenping-987123/archive/2010/08/04/1792149.html – yapingchen