Sorting string type DataTable with -ve numbers
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 1 of 1

Thread: Sorting string type DataTable with -ve numbers

  1. #1
    Join Date
    Mar 2014

    Sorting string type DataTable with -ve numbers

    I have built table3 by comparing table1(row) and table2(column).I want to sort the table3 but since my table3 is a taking strings the -ve sign is not considered how do I sort in Asc order conisdering the -ve values.

    I am new to this I know decimal.Tryparse can be used at the time when I am building table3 ,I dont know how to use it.Please some 1 help me solve this

    private static DataTable CompareTwoDataTable(DataTable table1, DataTable table2)
                DataTable table3 = new DataTable();
                DataRow dr = null;
                string filterExp = string.Empty;
                for (int i = 0; i < table1.Rows.Count; i++)
                    string col = table1.Rows[i]["Par Name"].ToString();
                    if (table2.Columns.Contains(col))
                        if (!table3.Columns.Contains(col))
                            filterExp = filterExp + col + " asc ,";
                        for (int j = 0; j < table2.Rows.Count; j++)
                            if (table3.Rows.Count != table2.Rows.Count)
                                dr = table3.NewRow();
                            table3.Rows[j][col] = (table2.Rows[j][col].ToString());
                DataView dv = new DataView(table3);
                filterExp = filterExp.TrimEnd(',');
                dv.Sort = filterExp;
                table3 = dv.ToTable();
                return table3;
    Last edited by HanneSThEGreaT; March 8th, 2014 at 01:43 AM. Reason: Added code tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This a survey!

HTML5 Development Center