private void btnAdd_Click(object sender, EventArgs e)
{
if (btnAdd.Text == "增加")
{
txtName.ReadOnly = false ;
txtPrice.ReadOnly = false ;
txtName.Text = "";
txtPrice.Text = "";
btnAdd.Text = "提交新增";
}
else
{
OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(adapter);
adapter.InsertCommand = commandBuilder.GetInsertCommand();
DataRow dr = ds.Tables["Food"].NewRow();
dr[0] = txtName.Text;
dr[1] = Convert.ToInt32(txtPrice.Text);
ds.Tables["Food"].Rows.Add(dr);
adapter.Update(ds, "Food");
ds.AcceptChanges();
}
}
private void btnMod_Click(object sender, EventArgs e)
{
if (btnMod.Text == "修改")
{
txtName.ReadOnly = false;
txtPrice.ReadOnly = false;
btnMod.Text = "提交修改";
}
else
{
OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(adapter);
adapter.UpdateCommand = commandBuilder.GetUpdateCommand();
DataRow dr = ds.Tables["Food"].Rows[rowIndex];
dr[0] = txtName.Text;
dr[1] = Convert.ToInt32(txtPrice.Text);
adapter.Update(ds, "Food");
ds.AcceptChanges();
}
}
private void btnDel_Click(object sender, EventArgs e)
{
OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(adapter);
adapter.DeleteCommand = commandBuilder.GetDeleteCommand();
DialogResult result = MessageBox.Show("确实要删除这条记录吗?", "删除确认");
if (result == DialogResult.OK)
ds.Tables["Food"].Rows[rowIndex].Delete();
adapter.Update(ds, "Food");
ds.AcceptChanges();
}
按下那三个键还是没有用啊 新人求教 如果有详细的代码就更好了 谢谢