伙伴们如何将数据库中的总和显示为textbox1和textbox2?
Private Sub totalquiz()
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()
sSQL = "Select sum(quiz) as score,sum(total) as total FROM prelimquiz where [username]='ad' And studentID='1111111'"
cmd.CommandText = sSQL
da.SelectCommand = cmd
da.Fill(dt)
textbox1.Text =dt.Rows[2].ToString()
textbox2.text =dt.rows[3].ToString()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
我不知道如何正确获取总和并显示到文本框。
答案 0 :(得分:0)
您的查询将只返回一条包含您想要的总和的记录
访问它只需执行以下操作
dt.Rows[0]["score"].ToString();
dt.Rows[0]["total"].ToString();
希望它会对你有所帮助
问候