首页 新闻 搜索 专区 学院

给DBConcurrencyException的冲突行赋值后为什么行的HasErrors属性为假了?

0
悬赏园豆:100 [已关闭问题] 关闭于 2010-05-03 20:27

下面的taskvision中代码

 移植到vS2008,按下面方法给dbEx.Row赋值后,dbEx.Row的hasErrors属性变成false了。是什么原因啊?

try
                {   
                    daTasks.Update(dsTasks, "Tasks");
                    break;
                }
                catch (DBConcurrencyException dbEx)
                {
                    // we're here because either the row was changed by someone else
                    // or deleted by the dba, let's try get the updated row
                    DataSet ds = new DataSet();

                    SqlCommand cmd = new SqlCommand("GetOneTask", sqlConn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    // get the updated row
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.SelectCommand.Parameters.Add("@TaskID", dbEx.Row["TaskID"]);
                    da.Fill(ds);

                    // if the row still exists
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        DataRow proposedRow = dbEx.Row.Table.NewRow();
                        DataRow databaseRow = ds.Tables[0].Rows[0];

                        // copy the attempted changes
                        proposedRow.ItemArray = dbEx.Row.ItemArray;

                        // set the row with what's in the database and then re-apply
                        // the proposed changes.
                        dbEx.Row.Table.Columns["TaskID"].ReadOnly = false;
                        dbEx.Row.ItemArray = databaseRow.ItemArray;//只要给dbEx.Row赋值,dbEx.Row.HasErrors就会变成false,重新设置dbEx.Row.RowError不为空也没用
                        dbEx.Row.AcceptChanges();
                        dbEx.Row.ItemArray = proposedRow.ItemArray;
                        dbEx.Row.Table.Columns["TaskID"].ReadOnly = true;

                        // note: because this row triggers an ADO.NET exception,
                        // the row was tagged with a rowerror property which we'll leave for the client app
                        return dsTasks;
                    }

wangd的主页 wangd | 初学一级 | 园豆:75
提问于:2010-04-29 21:41
< >
分享
所有回答(1)
0

dbEx.Row.ItemArray = databaseRow.ItemArray;//databaseRow.ItemArray它应该是空吧?

Astar | 园豆:40805 (高人七级) | 2010-04-30 08:38
怎样让修改了dbEx.Row的值后,dbEx.Row的错误信息还保留,让前台还可以检测到hasErrors?
支持(0) 反对(0) wangd | 园豆:75 (初学一级) | 2010-04-30 18:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册