0

伙计们如何将总和从数据库显示到 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

我不知道如何正确获取总和并显示到文本框。

4

1 回答 1

0

您的查询将只返回一条包含您想要的总和的记录

要访问它,只需执行以下操作

dt.Rows[0]["score"].ToString();
dt.Rows[0]["total"].ToString();

希望它会帮助你问候

于 2013-10-06T10:30:42.040 回答