2013-04-27 127 views
0

我想更新我的數據庫,當我運行我的項目並添加一個新行它的工作原理數據輸入到網格視圖,但它不會更新實際的數據庫。有什麼建議麼?更新數據庫c#

下面的代碼輸入到按鈕1:

DataRow dr = ds.Tables["details"].NewRow(); 
dr["Name"] = TextBox1.Text; 
dr["Price"] = TextBox2.Text; 
dr["Genre"] = TextBox3.Text; 
ds.Tables["details"].Rows.Add(dr); 
GridView1.DataSource = ds; 
GridView1.DataBind(); 
localhost.Service myws = new localhost.Service(); 

TextBox1.Text = ""; 
TextBox2.Text = ""; 
TextBox3.Text = ""; 

而且我使用Web服務:

public DataSet GetDetailsSet() 
{ 
DataSet detailsSet = new DataSet(); 
string database = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/shop.accdb;Persist Security Info=True"; 
OleDbConnection myConn = new OleDbConnection(database); 
string queryStr = "SELECT * FROM details"; 
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(queryStr, myConn); 
myConn.Open(); 
myDataAdapter.Fill(detailsSet, "Details"); 
myConn.Close(); 
return detailsSet; 
} 

我相信我需要在這個方法中添加某種方式更新,有什麼建議?

回答

0

將新行插入到「Details」數據表中,該表是數據庫服務器上原始表的本地副本。您必須使用update()方法更新原始表。可以使用不同的方法。

閱讀這篇文章。 How to update a database from a DataSet