国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

csharp: DataTable結(jié)構(gòu)相同的比較

2019-11-17 03:18:45
字體:
供稿:網(wǎng)友

csharp: DataTable結(jié)構(gòu)相同的比較

1        /// <summary>?        /// DataTable分頁?        /// </summary>?        /// <param name="dt">DataTable</param>?        /// <param name="PageIndex">頁索引,注意:從1開始</param>?        /// <param name="PageSize">每頁大小</param>?        /// <returns></returns>?        public static DataTable GetPagedTable(DataTable dt, int currentPageIndex, int pageSize)?        {??            //1?            //判斷當(dāng)前索引?            if (currentPageIndex == 0)?                return dt;?            //從數(shù)據(jù)集合拷貝數(shù)據(jù)?            DataTable newdt = dt.Copy();?            //數(shù)據(jù)清空?            newdt.Clear();?            //開始數(shù)據(jù)索引 = 當(dāng)前頁-1 x 每頁大小?            int rowbegin = (currentPageIndex - 1) * pageSize;?            //結(jié)束數(shù)據(jù)索引 = 當(dāng)前頁 x 每頁大小?            int rowend = currentPageIndex * pageSize;?            //開始數(shù)據(jù)索引 大于等于 當(dāng)前數(shù)據(jù)集合大小?            if (rowbegin >= dt.Rows.Count)?                return newdt;?            //結(jié)束數(shù)據(jù)索引 大于 當(dāng)前數(shù)據(jù)集合大小?            if (rowend > dt.Rows.Count)?                rowend = dt.Rows.Count;?            //遍歷數(shù)據(jù)?            for (int i = rowbegin; i <= rowend - 1; i++)?            {?                DataRow newdr = newdt.NewRow();?                DataRow dr = dt.Rows[i];?                foreach (DataColumn column in dt.Columns)?                {?                    newdr[column.ColumnName] = dr[column.ColumnName];?                }?                newdt.Rows.Add(newdr);?            }??            return newdt;???            //2?            //if (currentPageIndex == 0)?            //{?            //return dt;?            //}??            //DataTable newdt = dt.Clone();// dt.Copy();??            //int rowbegin = (currentPageIndex - 1) * pageSize;//當(dāng)前頁的第一條數(shù)據(jù)在dt中的位置?            //int rowend = currentPageIndex * pageSize;//當(dāng)前頁的最后一條數(shù)據(jù)在dt中的位置??            //if (rowbegin >= dt.Rows.Count)?            //{?            //    return newdt;?            //}??            //if (rowend > dt.Rows.Count)?            //{?            //    rowend = dt.Rows.Count;?            //}??            //DataView dv = dt.DefaultView;?            //for (int i = rowbegin; i <= rowend - 1; i++)?            //{?            //    newdt.ImportRow(dv[i].Row);?            //}??            //return newdt;??        }??        /// <summary>2         /// DataTable 結(jié)構(gòu)相同的比較?        /// ?        /// C# datatable comparison  Same  Different?        /// 涂聚文?        /// </summary>?        /// <param name="first"></param>?        /// <param name="second"></param>?        /// <returns></returns>?        public DataTable CompareTables(DataTable first, DataTable second)?        {?            first.TableName = "FirstTable";??            second.TableName = "SecondTable";??            //Create Empty Table??            DataTable table = new DataTable("Difference");??            try?            {?                //Must use a Dataset to make use of a DataRelation object?                using (DataSet ds = new DataSet())?                {?                    ds.Tables.AddRange(new DataTable[] { first.Copy(), second.Copy() });??                    //Get Columns for DataRelation??                    DataColumn[] firstcolumns = new DataColumn[ds.Tables[0].Columns.Count];???                    for (int i = 0; i < firstcolumns.Length; i++)?                    {??                        firstcolumns[i] = ds.Tables[0].Columns[i];??                    }???                    DataColumn[] secondcolumns = new DataColumn[ds.Tables[1].Columns.Count];??                    for (int i = 0; i < secondcolumns.Length; i++)?                    {??                        secondcolumns[i] = ds.Tables[1].Columns[i];??                    }???                    //Create DataRelation??                    DataRelation r = new DataRelation(string.Empty, firstcolumns, secondcolumns, false);??                    ds.Relations.Add(r);??                    //Create columns for return table??                    for (int i = 0; i < first.Columns.Count; i++)?                    {??                        table.Columns.Add(first.Columns[i].ColumnName, first.Columns[i].DataType);??                    }???                    //If First Row not in Second, Add to return table.??                    table.BeginLoadData();????                    foreach (DataRow parentrow in ds.Tables[0].Rows)?                    {??                        DataRow[] childrows = parentrow.GetChildRows(r);??                        if (childrows == null || childrows.Length == 0)??                            table.LoadDataRow(parentrow.ItemArray, true);??                    }??                    table.EndLoadData();??                }?            }?            catch (Exception ex)?            {??                throw ex;??            }??            return table;?        }

USE pubsGO--使用帶有簡單 CASE 函數(shù)的 SELECT 語句SELECT   Category =       CASE type         WHEN 'popular_comp' THEN 'Popular Computing'         WHEN 'mod_cook' THEN 'Modern Cooking'         WHEN 'business' THEN 'Business'         WHEN 'psychology' THEN 'Psychology'         WHEN 'trad_cook' THEN 'Traditional Cooking'         ELSE 'Not yet categorized'      END,   CAST(title AS varchar(25)) AS 'Shortened Title',   PRice AS PriceFROM titlesWHERE price IS NOT NULLORDER BY type, priceCOMPUTE AVG(price) BY typeGO--使用帶有簡單 CASE 函數(shù)和 CASE 搜索函數(shù)的 SELECT 語句 SELECT    'Price Category' =       CASE          WHEN price IS NULL THEN 'Not yet priced'         WHEN price < 10 THEN 'Very Reasonable Title'         WHEN price >= 10 and price < 20 THEN 'Coffee Table Title'         ELSE 'Expensive book!'      END,   CAST(title AS varchar(20)) AS 'Shortened Title'FROM titlesORDER BY priceGO--使用帶有 SUBSTRING 和 SELECT 的 CASE 函數(shù)SELECT SUBSTRING((RTRIM(a.au_fname) + ' '+    RTRIM(a.au_lname) + ' '), 1, 25) AS Name, a.au_id, ta.title_id,   Type =   CASE     WHEN SUBSTRING(ta.title_id, 1, 2) = 'BU' THEN 'Business'    WHEN SUBSTRING(ta.title_id, 1, 2) = 'MC' THEN 'Modern Cooking'    WHEN SUBSTRING(ta.title_id, 1, 2) = 'PC' THEN 'Popular Computing'    WHEN SUBSTRING(ta.title_id, 1, 2) = 'PS' THEN 'Psychology'    WHEN SUBSTRING(ta.title_id, 1, 2) = 'TC' THEN 'Traditional Cooking'  ENDFROM titleauthor ta JOIN authors a ON ta.au_id = a.au_id--


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 侯马市| 三江| 南乐县| 永嘉县| 四川省| 云和县| 阿图什市| 山西省| 板桥市| 萝北县| 临高县| 福海县| 万荣县| 黑山县| 兴安盟| 罗源县| 黑河市| 靖州| 仪征市| 化隆| 德州市| 谢通门县| 建瓯市| 宝鸡市| 达拉特旗| 滦南县| 贺州市| 镇安县| 油尖旺区| 南陵县| 江西省| 肃宁县| 牡丹江市| 吉水县| 南江县| 当涂县| 邳州市| 泸定县| 钟祥市| 忻城县| 闽侯县|