我最近写的代码,cellendedit后,希望能将当前的表UPDATE到数据库中。
现在出现的问题,我很迷惑。
1、在我完成当前cell的编辑,点击同一个DataGridView的其他cell时,程序运转正常。
2、在我不点击这个DataGridView的其他Cell完成编辑,点击Form中另一个DataGridView时,却无法将当前修改的cell所在行插入到数据库。我已经检查了插入前DataTable中确实已经修改过了,但是Update()的返回值却是0
注:另一个DataGridView是空的,我什么也没写,卡在这里。
下面这个是cellendedit()
private void category_dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
//current cell value
Object cellValue = this.category_dataGridView.Rows[e.RowIndex].Cells[1].Value;
if (e.RowIndex >= 0 && e.RowIndex < this.category_dataGridView.Rows.Count)
{
if (!this.category_Cell_BeginEditValue.Equals(this.category_Cell_EndEditValue))
{
try
{
//after validation, push copy of the current table into stack, then update database
this.officer.Category_DataTable.Rows[e.RowIndex].SetField<string>(1, this.category_Cell_EndEditValue);
this.officer.UpDateCategoryTable();
this.redo_Undo_Helper.Undo_Opeartion_Stack.Push(this.officer.Category_DataTable.Copy());
this.category_BindingSource.DataSource = officer.Category_DataTable; }
catch (Exception ex)
{
MessageBox.Show("这就是错误!\n" + ex.ToString());
//because of undo rebind the current table to datasource
this.officer.Category_DataTable = this.redo_Undo_Helper.GetLatestCategoryTableCopy();
this.category_BindingSource.DataSource = officer.Category_DataTable;
}
}
}
}这个是Update()
public void UpDateCategoryTable()
{
this.categories_Adapter.Update(this.category_table);
this.category_table.Clear();
this.categories_Adapter.Fill(this.category_table);
}请高人解惑。。
现在出现的问题,我很迷惑。
1、在我完成当前cell的编辑,点击同一个DataGridView的其他cell时,程序运转正常。
2、在我不点击这个DataGridView的其他Cell完成编辑,点击Form中另一个DataGridView时,却无法将当前修改的cell所在行插入到数据库。我已经检查了插入前DataTable中确实已经修改过了,但是Update()的返回值却是0
注:另一个DataGridView是空的,我什么也没写,卡在这里。
下面这个是cellendedit()
private void category_dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
//current cell value
Object cellValue = this.category_dataGridView.Rows[e.RowIndex].Cells[1].Value;
if (e.RowIndex >= 0 && e.RowIndex < this.category_dataGridView.Rows.Count)
{
if (!this.category_Cell_BeginEditValue.Equals(this.category_Cell_EndEditValue))
{
try
{
//after validation, push copy of the current table into stack, then update database
this.officer.Category_DataTable.Rows[e.RowIndex].SetField<string>(1, this.category_Cell_EndEditValue);
this.officer.UpDateCategoryTable();
this.redo_Undo_Helper.Undo_Opeartion_Stack.Push(this.officer.Category_DataTable.Copy());
this.category_BindingSource.DataSource = officer.Category_DataTable; }
catch (Exception ex)
{
MessageBox.Show("这就是错误!\n" + ex.ToString());
//because of undo rebind the current table to datasource
this.officer.Category_DataTable = this.redo_Undo_Helper.GetLatestCategoryTableCopy();
this.category_BindingSource.DataSource = officer.Category_DataTable;
}
}
}
}这个是Update()
public void UpDateCategoryTable()
{
this.categories_Adapter.Update(this.category_table);
this.category_table.Clear();
this.categories_Adapter.Fill(this.category_table);
}请高人解惑。。
解决方案 »
- 水晶报表2010不能显示png等透明图片,显示是黑色底,急急急急!!!
- 反射条用程序集如何传递命令行参数?
- c#怎么保存非字符串配置
- 实时大量数据采集的数据库选择及设计数据的存储方法
- c#编写的ActiveX控件里怎样调用客户端页面的javascript函数
- C# 在爬虫中使用户名和密码
- 系统安装使用后报错。
- 请问windows API的详细信息到那里去看啊?
- 在 WebClient 请求期间发生异常,如何处理进程错误?
- 请高手解惑---C#访问数据库问题
- 想在GOOGLE EARTH中添加动态模型
- vs2008中c#中怎样解决一个winform中几个按钮共用一个程序(例如 一个winform有3个退出)
{
InitializeComponent(); this.Text = StaticString.BUSSINESS_NAME + " Manage Stock"; this.category_BindingSource = new BindingSource();
this.officer = new StockOfficer();
this.redo_Undo_Helper = new Redo_Undo_Helper_ManageStockForm();
this.category_dataGridView.DataSource = this.category_BindingSource;
//push copy of the table from database to stack (original one)
this.redo_Undo_Helper.Undo_Opeartion_Stack.Push(officer.Category_DataTable.Copy());
//bind original one as data source
this.category_BindingSource.DataSource = officer.Category_DataTable;
//hide category ID
this.category_dataGridView.Columns[0].Visible = false;
this.category_dataGridView.Columns[1].Width = this.splitContainer1.Panel1.Width - 20;
}补充构造函数。
上面提到的两种奇怪现象,在点其他GRIDView来结束编辑时,datatable修改行的state是unchanged强制更改为modified时,数据库也是不作为,根本不理会。