日期:2014-05-20  浏览次数:20725 次

vb.net中linq求和问题
我在vb.net中试图用linq求合计,写了如下语句:
  Dim total = From R In DtSet.Sale_d
  Group R By R.SaleIdRow.Customer_Id Into G()
  Select New With {G.Key, .A = G.Sum(x >= x.Qty_Sale), .B = G.Sum(x >= x.Amt_Sale)}
DtSet为dataset,里面有两个表,主细表关系已建立关联。
但是写出来是不正确的 into后面不管用什么都会加上括号,视为方法,这样下面的就没法写了,我用c#写出来没什么问题,贴到vb.net里,他又自动得加上了括号,而且视为不正确的语句。
难道VB里面的写法不同吗?该如何写呢?
谢谢


------解决方案--------------------
VB.NET code

 Dim total = From R In DtSet.Table("Sale_d").AsEnumerable() _
  Group R By R..Field(Of Integer)("Customer_Id") Into G _
  Select New With _
     {
    key=G.Key, _
    .A =(From x In G Select x.Qty_Sale).Sum(), _
    .B = (From x In G Select x.Amt_Sale).Sum()
     }

------解决方案--------------------
VB.NET code
 Dim total = (From R In DtSet.Table("Sale_d").AsEnumerable() _
  Group R By R..Field(Of Integer)("Customer_Id") Into G).
  Select(Function(x)
     Dim a = (From x In G Select x.Qty_Sale).Sum()
     Dim b = (From x In G Select x.Amt_Sale).Sum()
     Return New With _
     {
        .key = G.Key, _
        .A = a, _
        .B = b
     }

------解决方案--------------------
http://msdn.microsoft.com/en-us/vbasic/bb737908
看看这个 也许能帮到你
------解决方案--------------------
VB.NET code

Public Sub Linq41()
    Dim words = New String() {"blueberry", "chimpanzee", "abacus", "banana", "apple", "cheese"}

    Dim wordGroups = From w In words _
                     Group w By Key = w(0) Into Group _
                     Select FirstLetter = Key, WordGroup = Group

    For Each g In wordGroups
        Console.WriteLine("Words that start with the letter '{0}':", g.FirstLetter)
        For Each w In g.WordGroup
            Console.WriteLine(w)
        Next
    Next

End Sub