在用强类型做底层数据更新GridView控件绑定的数据源时时出现“由于线程停在某个无法进行垃圾回收的点(可能是因为已对代码进行了优化),因此无法计算表达式的值”的错误,出现错误的源代码是:
Code
出现错误的源代码是:
public virtual bool AddNewMonthly(PlanManagementDataSet.UnitTargetDataTable ForAddTo)
{
ConnectionState previousConnectionState = this.Connection.State;
bool ReturnValue = true;
try
{
if (((this.Connection.State & ConnectionState.Open) != ConnectionState.Open))
this.Connection.Open();
//this.Transaction = this.Connection.BeginTransaction();
foreach (PlanManagementDataSet.UnitTargetRow NewRow in ForAddTo.Rows)
{
this.AndRow(NewRow.UnitID, NewRow.wbxssr_qnjh, NewRow.wbxssr_bysj, NewRow.wbxssr_bqzlj,
NewRow.wblr_qnjh, NewRow.wblr_bysj, NewRow.wblr_bqzlj,
NewRow.nbjssr_qnjh, NewRow.nbjssr_bysj, NewRow.nbjssr_bqzlj,
NewRow.nblr_qnjh, NewRow.nblr_bysj, NewRow.nblr_bqzlj,
NewRow.spcz_qnjh, NewRow.spcz_bysj, NewRow.spcz_bqzlj,
NewRow.spcl_bysj, NewRow.spcl_bqzlj, NewRow.bbny, NewRow.Periodicity, NewRow.Quarter);
}
//this.Transaction.Commit();
}
catch (System.Exception ex)
{
//this.Transaction.Rollback();
PlanManagement.Common.LogError.LogErrToFile(ex);
ReturnValue = false;
}
finally
{
//this.Transaction = null;
if ((previousConnectionState == ConnectionState.Closed))
this.Connection.Close();
}
return ReturnValue;
}
调用代码为:
Code
private void tbSave_Click(object sender, EventArgs e)
{
PlanManagementDataSet.UnitTargetDataTable Unit = new PlanManagementDataSet.UnitTargetDataTable();
Unit =(PlanManagementDataSet.UnitTargetDataTable)planManagementDataSet.UnitTarget.Copy();
try
{
this.unitTargetTableAdapter.AddNewMonthly(Unit);
MessageBox.Show("保存数据完成!","计划管理",MessageBoxButtons.OK,MessageBoxIcon.Information );
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}