首页 新闻 会员 周边

原生的DataSet中的Table与DataView.ToTable()产生的Table的区别?

0
悬赏园豆:10 [已关闭问题] 关闭于 2014-12-01 11:26

DataView ToTable()得到新的table对象,

当对这个新的table对象中的row 进行delete()时,是直接删除掉,而不是将row的状态设置为DataViewRowState.Deleted

 

测试:

         /// <summary>

        /// 过滤功能

        /// </summary>

        static void Filtersss(DataSet ds)

        {

            if (ds != null && ds.Tables[0].Rows.Count > 0)

            {

 

                DataTable newTable = null;

            

                newTable = ds.Tables[0].DefaultView.ToTable();

                newTable.Rows[0]["SourceTableKey"] = "Id=000000";

                ds.Tables[0].Rows[0].Delete();

                newTable.Rows[0].Delete();

                

            }

        }

 

为以下情况时候:

 

/// <summary>

        /// 过滤功能

        /// </summary>

        static void Filtersss(DataSet ds)

        {

            if (ds != null && ds.Tables[0].Rows.Count > 0)

            {

 

                DataTable newTable = null;

            

                newTable = ds.Tables[0].DefaultView.ToTable();

                newTable.Rows[0]["SourceTableKey"] = "Id=000000";

                //ds.Tables[0].Rows[0].Delete();

                //newTable.Rows[0].Delete();

                

            }

        }

Ds中第一条记录的SourceTableKey不变化

继续测试

/// <summary>

        /// 过滤功能

        /// </summary>

        static void Filtersss(DataSet ds)

        {

            if (ds != null && ds.Tables[0].Rows.Count > 0)

            {

 

                DataTable newTable = null;

            

                newTable = ds.Tables[0].DefaultView.ToTable();

                newTable.Rows[0]["SourceTableKey"] = "Id=000000";

                ds.Tables[0].Rows[0].Delete();

                //newTable.Rows[0].Delete();

                

            }

        }

 

newTable中的第一条记录依然存在,newTable中第一条记录没有变化

 

继续测试

/// <summary>

        /// 过滤功能

        /// </summary>

        static void Filtersss(DataSet ds)

        {

            if (ds != null && ds.Tables[0].Rows.Count > 0)

            {

 

                DataTable newTable = null;

            

                newTable = ds.Tables[0].DefaultView.ToTable();

                newTable.Rows[0]["SourceTableKey"] = "Id=000000";

                //ds.Tables[0].Rows[0].Delete();

                newTable.Rows[0].Delete();

                

            }

        }

ds中第一条记录依然没有被设置为deleted状态,但newTable第一条记录被删除

继续测试

/// <summary>

        /// 过滤功能

        /// </summary>

        static void Filtersss(DataSet ds)

        {

            if (ds != null && ds.Tables[0].Rows.Count > 0)

            {

 

                DataTable newTable = null;

            

                newTable = ds.Tables[0].DefaultView.ToTable();

                newTable.Rows[0]["SourceTableKey"] = "Id=000000";

                ds.Tables[0].Rows[0].Delete();

                newTable.Rows[0].Delete();

                

            }

        }

ds中第一条记录被设置为删除状态,deleted状态。newTable中第一条记录被删除,不见

 

据此推断ToTable()得到的Table对象,是个全新的对象,对源进行深Copy,但是一个问题始终未能理解,就是newTable中的Delete()为什么是直接删除掉,而不是设置Deleted状态?

Myisqq的主页 Myisqq | 初学一级 | 园豆:95
提问于:2014-11-27 11:16
< >
分享
所有回答(2)
0

比较的话,不要拿牛和马进行好不好。

爱编程的大叔 | 园豆:30839 (高人七级) | 2014-11-27 11:40

我因不知道DataView.ToTable()的细节,才有此问题前来询问,而我问问题的目的在于解决问题,而不是听别人这样说,请勿跑题,谢谢

支持(0) 反对(0) Myisqq | 园豆:95 (初学一级) | 2014-11-27 11:53

@Myisqq: 

听不懂的话,你愿意思考也行,听不懂回答又不愿意不思考,我能有什么办法呢?

关键词

牛、马

支持(0) 反对(0) 爱编程的大叔 | 园豆:30839 (高人七级) | 2014-11-27 12:02
0

ToTable()出来的记录都是Added状态,这个状态使用Delete()方法会被彻底删除掉

Myisqq | 园豆:95 (初学一级) | 2014-12-01 11:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册