从列的总和值MySQL获取总值

时间:2011-08-29 17:44:35

标签: mysql vb.net

好的,我在2天前了解到这个问题: -

SELECT SUM(DTotal) AS Monthly FROM bdailytotal

但我将如何查看总和的总值?我一直在寻找这个,但我得到的大部分答案都是针对PHP的。有人可以告诉我如何将这个总值分配给VB.NET中的变量吗?

或者教我如何将总价值分配到另一个表格。

2 个答案:

答案 0 :(得分:1)

使用ExecuteScalar()尝试类似的内容:

Dim objConn As MySql.Data.MySqlClient.MySqlConnection
Dim objCmd As MySql.Data.MySqlClient.MySqlCommand
Dim strConnString,strSQL As String

strConnString = "Server=localhost;User Id=root; Password=root; Database=mydatabase;"
objConn = New MySql.Data.MySqlClient.MySqlConnection(strConnString)
objConn.Open()

strSQL = "SELECT SUM(DTotal) AS Monthly FROM bdailytotal"

objCmd = New MySql.Data.MySqlClient.MySqlCommand()
With objCmd
.Connection = objConn
.CommandType = CommandType.Text
.CommandText = strSQL
End With

Dim myScalar As Integer = Convert.ToInt32(objCmd.ExecuteScalar())

答案 1 :(得分:0)

尝试以下方法:

While dr.Read()
Dim monthly = dr("Monthly")
End While

MsgBox(monthly)