Vb.net 如何获得数据库访问的总数或总和
我有一段代码,它将数据库过滤并显示到datagridview 前Vb.net 如何获得数据库访问的总数或总和,vb.net,Vb.net,我有一段代码,它将数据库过滤并显示到datagridview 前 得分|总分 25 | 30 20 | 40 25 | 25 现在,我怎样才能得到测验的总数和“scoretotal”的总数,或者我应该说,怎样才能得到只有datagridview显示的内容的总数 Private Sub datagrid() Dim conn As New OleDbConnection Dim cmd As New OleDbCommand Dim da As New
得分|总分
25 | 30
20 | 40
25 | 25
现在,我怎样才能得到测验的总数和“scoretotal”的总数,或者我应该说,怎样才能得到只有datagridview显示的内容的总数
Private Sub datagrid()
Dim conn As New OleDbConnection
Dim cmd As New OleDbCommand
Dim da As New OleDbDataAdapter
Dim dt As New DataTable
Dim sSQL As String = String.Empty
Try
conn = New OleDbConnection(Get_Constring)
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.Text
sSQL = "SELECT score as score, total as total FROM prelimquiz"
sSQL = sSQL & " where username like '%" & Administrator.lblusername.Text & "%' and studentid like '%" & Me.Label25.Text & "%'"
cmd.CommandText = sSQL
da.SelectCommand = cmd
da.Fill(dt)
Me.DataGridView1.DataSource = dt
If dt.Rows.Count = 0 Then
End If
Catch ex As Exception
MsgBox(ErrorToString)
Finally
conn.Close()
End Try
End Sub
linq将非常感谢您的任何建议和建议:
Dim dtAsEnum = dt.AsEnumerable
Dim ScoreResult = dtAsEnum.Sum(Function(row) row.Field(Of Integer)("score"))
Dim TotalResult = dtAsEnum.Sum(Function(row) row.Field(Of Integer)("total"))
为什么将乘法分数作为分数,将总数作为总数?我将如何将其显示到textbox1和textbox2?textbox1.Text=分数结果和textbox2.Text=TotalResult@lomed我想你的意思是
textbox1.Text=scoresult.ToString()
等等。