如何在文本框中显示总和?

时间:2013-10-06 08:03:51

标签: vb.net

我刚刚搜索了vb.net示例,了解如何获取“数据库的总和”,现在我得到了这个但是如何在textbox1和textbox2中显示它?

但我不知道如何将其插入文本框。

 Try
        conn = New OleDbConnection(Get_Constring)
        conn.Open()
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
       sSQL=" Select userName,sum(quiz) as SumQuiz,sum(total) as Total From xxx where [username]='ad' And studentID='1111111'"
        cmd.CommandText = sSQL
        da.SelectCommand = cmd

1 个答案:

答案 0 :(得分:1)

我的VB并不那么强大。您可以尝试OleDbDataReader将数据读入变量。然后将变量的值分配给textbox1.Texttextbox2.Text

Dim user As String
Dim sumQuiz As Integer
Dim total As Integer
Try
    conn = New OleDbConnection(Get_Constring)
    conn.Open()
    cmd.Connection = conn
    cmd.CommandType = CommandType.Text
   sSQL=" Select userName,sum(quiz) as SumQuiz,sum(total) as Total From xxx where [username]='ad' And studentID='1111111'"
    cmd.CommandText = sSQL
    OleDbDataReader dr = cmd.ExecuteReader()
    If dr.Read() Then
        set user = Convert.ToString(dr["userName"])
        set sumQuiz = Convert.ToInt32(dr["SumQuiz"])
        set total = Convert.ToInt32(dr["Total"])
    End If