Find the Largest Integer in Column

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

Hi,
I have a table which contains a unique value in a column called "Idx",
which is a smallint data type. I need to find the maximum value in
this column, which I have been attempting to do with this command:

Dim intMaxIdx As Integer = CInt(Me.ds.myTable.Compute("MAX(Idx)",
Nothing))

I noticed that this command treats the values like strings rather than
integers. For example, if I have a value of 2 and a value of 11, the
value 2 is returned as the maximum value. I can't figure out how to
execute this so that it handles them like numbers, not strings.

Can anybody suggest anything?

Thanks,
Randy
 
Randy said:
Hi,
I have a table which contains a unique value in a column called "Idx",
which is a smallint data type. I need to find the maximum value in
this column, which I have been attempting to do with this command:

Dim intMaxIdx As Integer = CInt(Me.ds.myTable.Compute("MAX(Idx)",
Nothing))

I noticed that this command treats the values like strings rather than
integers. For example, if I have a value of 2 and a value of 11, the
value 2 is returned as the maximum value. I can't figure out how to
execute this so that it handles them like numbers, not strings.

Can anybody suggest anything?

A DataTable with a numeric field computes the aggregate numerically,
just as expected. The result is even numeric.

(Sorry about the C# code in the VB forum, but that's what I work with.)

DataTable table = new DataTable();
table.Columns.Add(new DataColumn("test", typeof(short)));
table.Rows.Add(1);
table.Rows.Add(2);
table.Rows.Add(11);
table.Rows.Add(5);
table.Rows.Add(3);
short result = (short)table.Compute("max(test)", null);
Console.WriteLine(result);

Output:
11

Ergo, something is not correct in what you describe.
 
Thanks, but I'm not looking for the aggregate, I'm looking for the
maximum value in the column.
 
The first step would be to check the client side type of this column.Are you
sure you don't convert this to a string when extracting the data from the db
? What Göran wanted to say is that the data type of the column is taken
into account for the calculation i.e. for now it is likely that this
smallint value is stored as a string client side and it would work if it was
really stored as a numeric value...
 
Back
Top