[求助]为什么新增好用,删除和修改不好用?
更新数据库时提示错误信息:Form_load:
sqlDataAdapter1=new SqlDataAdapter("select * from 组织机构编码表",conn);
sqlDataAdapter1.Fill(tblSetOrgInfo);//读入数据
SqlCommandBuilder cb = new SqlCommandBuilder(sqlDataAdapter1);
DataTable tempDataTable = tblSetOrgInfo.Copy();//将组织机构表另存一份为tempDataTable
DataView viewSetOrgInfo = new DataView(tempDataTable);//新建一个数据视图
删除_Click:
string strEnterpriseID = this.textBox3.Text.Trim();
string strFilter = "单位编号 = '" + strEnterpriseID + "'";
try
{
DataRow[] myRow = this.tblSetOrgInfo.Select(strFilter);
if (myRow.Length ==1)//找到该条记录,并从数据集中删除
{
string strFilter_ParentIndex = "ParentIndex = '" + myRow[0]["AbsIndex"].ToString().Trim() + "'";
DataRow[] myChildRows = this.tblSetOrgInfo.Select(strFilter_ParentIndex);
myRow[0].Delete();
foreach (DataRow aRow in myChildRows)//如果该项目有子项,则将子项也一并全部删除
{
aRow.Delete();
}
this.sqlDataAdapter1.Update(this.tblSetOrgInfo); //更新出错!
}
}