Import flash. events. Event;

Source: Internet
Author: User

[Csharp] DataView DV = dtLineTypeURL. DefaultView;
DataTable dtTmp = DV. ToTable ("tb1", true, "LineType"); // use distinct for LineType
DtLineTypeURL = dtTmp;

DataView DV = dtLineTypeURL. DefaultView;
DataTable dtTmp = DV. ToTable ("tb1", true, "LineType"); // use distinct for LineType
DtLineTypeURL = dtTmp; or

 

[Csharp] dtLineTypeURL = dtLineTypeURL. DefaultView. ToTable (true, "LineType"); // use distinct for LineType

DtLineTypeURL = dtLineTypeURL. DefaultView. ToTable (true, "LineType"); // use distinct for LineType
Note: The dataTable obtained in the preceding method only has the LineType column, and other columns are discarded.

 


If you only want to perform distinct on a column and keep other columns, use the following:


[Csharp] # region deletes duplicate columns of a able, similar to distinct
/// <Summary>
/// Delete the repeated DataTable columns, similar to distinct
/// </Summary>
/// <Param name = "dt"> DataTable </param>
/// <Param name = "Field"> Field name </param>
/// <Returns> </returns>
Public static DataTable DeleteSameRow (DataTable dt, string Field)
{
ArrayList indexList = new ArrayList ();
// Locate the row index to be deleted
For (int I = 0; I <dt. Rows. Count-1; I ++)
{
If (! IndexList. Contains (I ))
{
For (int j = I + 1; j <dt. Rows. Count; j ++)
{
If (dt. Rows [I] [Field]. ToString () = dt. Rows [j] [Field]. ToString ())
{
IndexList. Add (j );
}
}
}
}
 
IndexList. Sort ();
 
// Delete a row based on the index list to be deleted
For (int I = indexList. Count-1; I> = 0; I --)
{
Int index = Convert. ToInt32 (indexList [I]);
Dt. Rows. RemoveAt (index );
}
Return dt;
}
 
# Endregion

# Region Delete the repeated DataTable columns, similar to distinct
/// <Summary>
/// Delete the repeated DataTable columns, similar to distinct
/// </Summary>
/// <Param name = "dt"> DataTable </param>
/// <Param name = "Field"> Field name </param>
/// <Returns> </returns>
Public static DataTable DeleteSameRow (DataTable dt, string Field)
{
ArrayList indexList = new ArrayList ();
// Locate the row index to be deleted
For (int I = 0; I <dt. Rows. Count-1; I ++)
{
If (! IndexList. Contains (I ))
{
For (int j = I + 1; j <dt. Rows. Count; j ++)
{
If (dt. Rows [I] [Field]. ToString () = dt. Rows [j] [Field]. ToString ())
{
IndexList. Add (j );
}
}
}
}

IndexList. Sort ();

// Delete a row based on the index list to be deleted
For (int I = indexList. Count-1; I> = 0; I --)
{
Int index = Convert. ToInt32 (indexList [I]);
Dt. Rows. RemoveAt (index );
}
Return dt;
}
 
# Endregion

Call method:

DtLineTypeURL = Common. DeleteSameRow (dtLineTypeURL, "LineType"); // use distinct for LineType

 

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.