Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2007

Tip: Looking for answers? Try searching our database.

Stupid Sorting!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cliff - 29 Mar 2007 13:38 GMT
in the table:

dt.Columns.Add("Session Duration Seconds",
System.Type.GetType("System.Int32"));

---------------

then the following code to try and sort the table based on that colum

-------------

dv = new DataView(ds.Tables["vpninfo"]);

dv.Sort = "Session Duration Seconds";

foreach (DataRowView dr in dv)
     {
            Debug.WriteLine(dr["Session Duration Seconds"]);
     }

--------------

The output from the debug line

1002
10290
10378
105996
1061542
109
1111
1128591
1136
11483
1164

now I know thats not in order of size.....its in alphabetical order!

how can it get this to sort properly?

Any help appreciated...this one's driving me NUTS!

Cliff Dabbs
Laura T. - 29 Mar 2007 14:21 GMT
Try dt.Columns.Add("Session Duration Seconds",typeof(System.Int32));
instead.

> in the table:
>
[quoted text clipped - 39 lines]
>
> Cliff Dabbs
Cliff - 29 Mar 2007 14:31 GMT
> Try dt.Columns.Add("Session Duration Seconds",typeof(System.Int32));
> instead.
[quoted text clipped - 44 lines]
>
> - Show quoted text -

Hi,

Thanks for the quick answer, but having tried that, the results are
identical....

Cliff.
ClayB - 29 Mar 2007 14:56 GMT
If you write out  Debug.WriteLine(dr["Session Duration
Seconds"].GetType());, do you see int or string? I suspect string.

What code are you using to place the numbers into the DataTable? The
code below works as expected for me.

DataTable dt = new DataTable("MyTable");

           Random r = new Random();
           dt.Columns.Add(new DataColumn("Some System.Int32",
typeof(System.Int32)));

           for (int i = 0; i < 5; ++i)
           {
               DataRow dr = dt.NewRow();
               dr[0] = r.Next(1000000);
               dt.Rows.Add(dr);
           }

           DataView dv = new DataView(dt);
           dv.Sort = "Some System.Int32";
          foreach(DataRowView drv in dv)
               Console.WriteLine(drv["Some System.Int32"]);
===============
Clay Burch
Syncfusion, Inc.
Cliff - 29 Mar 2007 15:51 GMT
> If you write out  Debug.WriteLine(dr["Session Duration
> Seconds"].GetType());, do you see int or string? I suspect string.
[quoted text clipped - 22 lines]
> Clay Burch
> Syncfusion, Inc.

Clay,

Thanks for that, yes its coming out as System.String, so my Colum Add
with the Type of System.Int32 obveiously isn't working.

The DataTable is actually being made up by copying from another data
structure in memory, I'm making it to DataTable so that I can use it
in Web stuff easily

the actual code is:

           for (int i = 0; i < vbTable.GetLength(0); i++)
           {
               DataRow dr = dt.Rows.Add();

               for (int j = 1; j < vbTable[i].GetLength(0); j++)
               {
                   try
                   {
                       if (vbTable[i][j] != null)
                       {
                           dr[j] = vbTable[i][j].Value;
                       }
                   }
                   catch (System.NullReferenceException)
                   {
                       dr[j] = "";
                   }
               }
           }

although the only bit of that that actually does anything is

dr[j] = vbTable[i][j].Value;

which cycles through each of the colums on each of the rows adding the
STRING value from the source data structure. so yes, here it is a
string thats being passed. vbTable only contains strings.

However, becuase of the way I set the table up, at the point "Session
Duration Seconds" is copied across, I was expecting it to do a
conversion automaticlally...which obveiously isn't happening either!

How can I make that line so it converts to the appropriate type?

Thanks again...

Cliff.
Cliff - 29 Mar 2007 16:41 GMT
> > If you write out  Debug.WriteLine(dr["Session Duration
> > Seconds"].GetType());, do you see int or string? I suspect string.
[quoted text clipped - 73 lines]
>
> - Show quoted text -

Got it...thanks guys...

I think it was a combination of the number overflowing from 32 to 64
bits and some crap coding on my part....

Thanks again.

Cliff.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.