我正在尝试更新我的数据库,当我运行我的项目并添加一个新行时,它的工作数据被输入到 gridview 中,但它不会更新实际的数据库。有什么建议么?
在button1中输入以下代码:
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;
}
我相信我需要以某种方式在此方法中添加更新,有什么建议吗?