0

我刚刚通过 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
4

1 回答 1

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
于 2013-10-06T12:46:55.423 回答