Csharp 两个DataTable或DataView互换,可以用来加密解密

        /// <summary>
        /// 涂聚文 geovindu.blog.163.com
        /// www.dusystem.com  www.dupcit.com
       /// 2011-05-28
      /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        static DataTable GetDecTable(DataTable table)
        {
            if (!object.Equals(table, null))//
            {
                DataTable tableDec = new DataTable();
                tableDec.Columns.Add("序号", typeof(string));
                tableDec.Columns.Add("员工编号", typeof(string));
                tableDec.Columns.Add("姓名", typeof(string));
                tableDec.Columns.Add("身份证号", typeof(string));
                tableDec.Columns.Add("入职时间", typeof(DateTime));
                foreach (DataRow row in table.Rows) // Loop over the rows.
                {
                    tableDec.Rows.Add(row["序号"].ToString(), row["员工编号"].ToString(),  row["姓名"].ToString(),  row["身份证号"].ToString(), row["入职时间"].ToString());

                }
                return tableDec;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 涂聚文 締友計算機信息技術有限公司,捷為工作室,geovindu.blog.163.com
        /// www.dusystem.com  www.dupcit.com
       /// 2011-05-28
      /// </summary>
        /// <param name="view"></param>
        /// <returns></returns>
        static DataView getDecView(DataView view)
        {
            
            if (!object.Equals(view, null))
            {
                
                DataTable tableDec = new DataTable();
                tableDec.Columns.Add("序号", typeof(string));
                tableDec.Columns.Add("员工编号", typeof(string));
                tableDec.Columns.Add("姓名", typeof(string));
                tableDec.Columns.Add("身份证号", typeof(string));
                tableDec.Columns.Add("入职时间", typeof(DateTime));
                DataView dv = new DataView(tableDec);
                //DataSet dset = new DataSet();
                //dset = hr.HrestDataSet();
                dv.AllowNew = true;
                
                //rowView["ProductName"] = "New Product Name";
                //dv.AddNew();
                //foreach (DataRow theRow in thisDataSet.Tables["Employee"].Rows)
                //{
                //    Console.WriteLine(theRow["ID"] + "\t" + theRow["FirstName"]);
                //}

                //DataView view = new DataView(ds.Tables[0]);
                foreach (DataRowView drv in view)
                {
                    DataRowView rowView = dv.AddNew();
                    rowView["序号"] = drv["序号"].ToString();
                    rowView["员工编号"] =drv["员工编号"].ToString();
                    rowView["姓名"] = drv["姓名"].ToString;
                    rowView["身份证号"] = drv["身份证号"].ToString();
                    rowView["入职时间"] = drv["入职时间"].ToString();
                }

                //// find the record for Rick
                //view.RowFilter = "Name = 'Evy'";
                //foreach (DataRowView drv in view)
                //{
                //    Console.WriteLine(drv["Name"].ToString());
                //}
                return dv;
            }
            else
            {
                return null;
            }
        }
posted @ 2011-05-28 10:45  ®Geovin Du Dream Park™  阅读(957)  评论(0编辑  收藏  举报