How to get a new DataTable that does not duplicate a fixed column

Source: Internet
Author: User
Tags count tostring
#region Get new DataTable///<summary>///for fixed columns do not duplicate new DataTable///</summary>///<para M name= "DT" > Datatable</param>///containing duplicate data <param name= "colname" > Need to verify duplicate column names </param>///<retu Rns> new Datatable,colname columns are not duplicated, table-style remains unchanged </returns> private DataTable getdistincttable (DataTable DT, string colname) {if (dt. Rows.Count = 0 | | Dt.    
        Rows.Count = = 1) {WriteFile ("getdistincttable The number of rows passed into DT is less than or equal to 1" + "\ r \ n", LogName, out outmessage);    
    return DT; } DataView dv = dt.    
    DefaultView; Duplicate column name DataTable Dtcardno = DV in DV filter DV.    
    ToTable (True, colname);    
    DataTable Pointdt = new DataTable ();    
    ToTable () Creates and returns a new DataTable based on the rows in the existing DataView. The output table contains the same column POINTDT = DV as the input table.    
    ToTable ();    
    Pointdt.clear (); for (int i = 0; i < DtCardNo.Rows.Count i++) {try {//dr takes the DAT that is returned by select Arow[] in the firstA piece of data//if DTCARDNO.ROWS[I][0]. There is no value in ToString () that will count out the error if (!string) that the group exceeded the index bounds. IsNullOrEmpty (Dtcardno.rows[i][0]. ToString ())) {DataRow dr = dt. Select (colname + "= '" + dtcardno.rows[i][0].    
                ToString () + "'") [0]; Datarow.itemarray uses an array to get or set all the values for this row Pointdt.Rows.Add (Dr.    
            ItemArray);    
    } catch (Exception ee) {//can write error to log file}}    
return POINTDT; } #endregion

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/aspx/

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.