views:

33

answers:

2

In a LINQ To SQL query, how can I apply a Round function on a column in my output?

My query is

  From s In oRecelDB.Items Where s.BIN = 'ABC' Select s.ITEMNMBR, s.QUANTITY

and the results are

ITEM I   35.0000
ITEM 2   45.0000
ITEM 3   23.0000

I want to remove the .00000 from the Second column value. How to do that in my query?

+3  A: 

Simply convert the value to an Integer:

From s in oRecelDB.Items Where s.BIN = 'ABC' _
    Select s.ITEMNMBR, Quantity = System.Convert.ToInt32(s.QUANTITY)
Justin Niessner
Is this the C# form ? Can i have the vb.net equivalent ?
Shyju
@Shyju - That should be the VB.NET form.
Justin Niessner
Shyju
@Shyju - I just updated. I forgot to give a name to the result of the conversion. You should be good to go now.
Justin Niessner
that Worked.Thanks
Shyju
+1  A: 

If you really wanted to simply drop the decimal values use Math.Floor:

From s In oRecelDB.Items Where s.BIN = 'ABC' _
  Select s.ITEMNMBR, Math.Floor(s.QUANTITY)

It'll return you a decimal datatype. That may/not be what you want.

p.campbell