Csharp: Comparison of the same DataTable Structure

Source: Internet
Author: User

         
         
         
         
         
         
          DataTable GetPagedTable(DataTable dt,  currentPageIndex,  pageSize)
        {

            
             (currentPageIndex == )
                 dt;
            
            DataTable newdt = dt.Copy();
            
            newdt.Clear();
            
             rowbegin = (currentPageIndex - ) * pageSize;
            
             rowend = currentPageIndex * pageSize;
            
             (rowbegin >= dt.Rows.Count)
                 newdt;
            
             (rowend > dt.Rows.Count)
                rowend = dt.Rows.Count;
            
             ( i = rowbegin; i <= rowend - ; i++)
            {
                DataRow newdr = newdt.NewRow();
                DataRow dr = dt.Rows[i];
                 (DataColumn column  dt.Columns)
                {
                    newdr[column.ColumnName] = dr[column.ColumnName];
                }
                newdt.Rows.Add(newdr);
            }

             newdt;


            

        }

                   
         
         
         
         
         DataTable CompareTables(DataTable first, DataTable second)
        {
            first.TableName = ;

            second.TableName = ;

            

            DataTable table =  DataTable();

            
            {
                
                 (DataSet ds =  DataSet())
                {
                    ds.Tables.AddRange( DataTable[] { first.Copy(), second.Copy() });

                    

                    DataColumn[] firstcolumns =  DataColumn[ds.Tables[].Columns.Count];


                     ( i = ; i < firstcolumns.Length; i++)
                    {

                        firstcolumns[i] = ds.Tables[].Columns[i];

                    }


                    DataColumn[] secondcolumns =  DataColumn[ds.Tables[].Columns.Count];

                     ( i = ; i < secondcolumns.Length; i++)
                    {

                        secondcolumns[i] = ds.Tables[].Columns[i];

                    }


                    

                    DataRelation r =  DataRelation(.Empty, firstcolumns, secondcolumns, );

                    ds.Relations.Add(r);

                    

                     ( i = ; i < first.Columns.Count; i++)
                    {

                        table.Columns.Add(first.Columns[i].ColumnName, first.Columns[i].DataType);

                    }


                    

                    table.BeginLoadData();



                     (DataRow parentrow  ds.Tables[].Rows)
                    {

                        DataRow[] childrows = parentrow.GetChildRows(r);

                         (childrows ==  || childrows.Length == )

                            table.LoadDataRow(parentrow.ItemArray, );

                    }

                    table.EndLoadData();

                }
            }
             (Exception ex)
            {

                 ex;

            }

             table;
        }

 

USE pubsGO -- USE the SELECT statement with a simple CASE function SELECT Category = CASE type WHEN 'popular _ comp 'then' popular Computing 'when' mod _ cooke' THEN 'modern cooking' when' business 'then' Business 'when' psychology 'then' Psychology 'when' trad _ cooke' 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 typ E, priceCOMPUTE AVG (price) BY typeGO -- SELECT 'price Category '= case when Price is null then' Not yet priced 'when price <10 THEN 'Very Reasonable using the SELECT statement with simple CASE function and CASE search function 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 -- use the CASE function with SUBSTRING and select substring (RTRIM (. au_fname) + ''+ RTRIM (. au_lname) + ''), 1, 25) AS Name,. au_id, ta. title_id, Type = case when substring (ta. title_id, 1, 2) = 'bus' 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 =. au_id --

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.