2016.1.22 利用LINQ实现DataSet内多张DataTable关联查询操作(目前未发现太大价值)

DataSet ds = new DataSet();

            DataTable t1 = DBFactorySingleton.GetInstance().Factory.GetDataTable(sql_ndp).Copy();

            t1.TableName = "t1";

            DataTable t2 = DBFactorySingleton.GetInstance().Factory.GetDataTable(sql_naip).Copy();

            t2.TableName = "t2";

            ds.Tables.Add(t1);

            ds.Tables.Add(t2);

 

            var restable =

                from f1 in ds.Tables[0].AsEnumerable()

                from f2 in ds.Tables[1].AsEnumerable()

                where f1.Field<string>("类型") + f1.Field<string>("名称") + f1.Field<string>("识别") == f2.Field<string>("类型") + f2.Field<string>("名称") + f2.Field<string>("识别")

                //where f1.Field<string>("类型") + f1.Field<string>("名称")=="VOR_DME英德"

                select new

                {

                    c1 = f1.Field<string>("源"),

                    c2 = f1.Field<string>("类型"),

                    c3 = f1.Field<string>("名称"),

                    c4 = f1.Field<string>("识别"),

                    c5 = f1.Field<string>("磁差"),

                    c6 = f1.Field<string>("坐标"),

                    c7 = f1.Field<string>("频率"),

                    c8 = f1.Field<string>("波道"),

                    c9 = f1.Field<string>("天线高"),

                    c10 = f1.Field<string>("强制报告")

                };

            gdc_pmatch.DataSource = restable.ToArray();

posted on 2016-10-15 17:51  mol1995  阅读(277)  评论(0编辑  收藏  举报

导航