A DataTable in which varchar is converted to Double after reordering.

Source: Internet
Author: User

The DataTable queries a field for a varchar type. But the numbers that are stored in them need to be sorted. But if the direct sort is wrong. Because of the varchar type, you need to convert it.

Method One:

Dt. Columns.Add ("Ipersonordersort", System.Type.GetType ("System.Double"));
Dt. columns["Ipersonordersort"]. Expression = "Convert (tagvalue, ' system.double ')";
DataView dv = new DataView (DT);
Dv. Sort = "Ipersonordersort asc";//Sort before conversion to DataView

Method Two:

Add a column for sorting when the SQL statement is filtered.
For example:

Select Percent as Strpercent,cast (Percent as int) as Intpercent
From Table.

Then a column intpercent int is automatically generated in the dataset.
In dataview.sortexpression = "intpercent"; Rather than "strpercent";

A DataTable in which varchar is converted to Double after reordering.

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.