如何获取我的Linq声明给我不同的结果显示 [英] How Do I Get My Linq Statement To Give Me Different Results Displayed

查看:74
本文介绍了如何获取我的Linq声明给我不同的结果显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个linq声明,我将字母成绩转换成数字来计算gpa,任何人都可以告诉我为什么无论我点击什么等级我都得到相同的每个68的gpa?也许有人可以查看我的代码并给我一个答案或提示谢谢












I have a linq statement where i turned letter grades into numbers to calculate a gpa can anyone tell me why no matter what grade i click i get the same gpa of 68 for each one? maybe someone can look over my code and give me an answer or hint thanks






Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click


        Dim dic As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)
        dic.Add("A", 4)
        dic.Add("B", 3)
        dic.Add("C", 2)
        dic.Add("D", 1)
        dic.Add("F", 0)

        Dim gpa = Aggregate Grade In CoursesDataSet.tblCourses.AsEnumerable()
           Select Grade.Field(Of Integer)("CreditHours") * dic(Grade.Field(Of String)("Grade"))
           Into Sum()


        MessageBox.Show("GPa:" & gpa.ToString("C2"),
                      "College Courses", MessageBoxButtons.OK,
MessageBoxIcon.Information)
    End Sub

End Class







这个网址是关于如何显示成绩的图片在数据库上

http://i59.tinypic.com/2vinzeo.jpg [< a href =http://i59.tinypic.com/2vinzeo.jpgtarget =_ blanktitle =New Window> ^ ]

推荐答案

您只需要其中 [< a href =https://msdn.microsoft.com/en-us/library/vstudio/bb549418%28v=vs.100%29.aspxtarget =_ blanktitle =New Window> ^ ]查询内的指令;)



All you need is Where[^] instruction inside query ;)

Dim sID As String = "ValueFromDataGridViewCell" 'for example: CS100 
Dim gpa = Aggregate Grade In CoursesDataSet.tblCourses.AsEnumerable()
   Where Grade.Field(Of String)("ID").Contains(sId)
   Select Grade.Field(Of Integer)("CreditHours") * dic(Grade.Field(Of String)("Grade"))
   Into Sum()


这篇关于如何获取我的Linq声明给我不同的结果显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆