Home All Groups Group Topic Archive Search About
Author
29 Mar 2007 12:38 PM
Cliff
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

Author
29 Mar 2007 1:21 PM
Laura T.
Try dt.Columns.Add("Session Duration Seconds",typeof(System.Int32));
instead.


Show quote
"Cliff" <J***@ballsdeep.net> ha scritto nel messaggio
news:1175171902.196321.60540@p15g2000hsd.googlegroups.com...
> 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
>
Author
29 Mar 2007 1:31 PM
Cliff
Show quote
On 29 Mar, 14:21, "Laura T." <L***@NOWHERE.COM> wrote:
> Try dt.Columns.Add("Session Duration Seconds",typeof(System.Int32));
> instead.
>
> "Cliff" <J***@ballsdeep.net> ha scritto nel messaggionews:1175171902.196321.60***@p15g2000hsd.googlegroups.com...
>
>
>
> > 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!
>
> >CliffDabbs- Hide quoted text -
>
> - Show quoted text -

Hi,

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

Cliff.
Author
29 Mar 2007 1:56 PM
ClayB
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.
Author
29 Mar 2007 2:51 PM
Cliff
Show quote
On 29 Mar, 14:56, "ClayB" <c***@syncfusion.com> wrote:
> 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.

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.
Author
29 Mar 2007 3:41 PM
Cliff
Show quote
On 29 Mar, 15:51, "Cliff" <J***@ballsdeep.net> wrote:
> On 29 Mar, 14:56, "ClayB" <c***@syncfusion.com> wrote:
>
>
>
>
>
> > 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.
>
> 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.- Hide quoted text -
>
> - 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.

AddThis Social Bookmark Button