Get the total value from a summation value of column, MySQL
Okay, I learned about this query 2 days ago:-
SELECT SUM(DTotal) AS Monthly FR开发者_如何学GoOM bdailytotal
but how I'm going to view the total value of the summation? I had been searching for this but most of the answers I get is for PHP. Can someone show me how to assign that total value to a variable in VB.NET?
Or teach me how to assign that total value to another table.
Try something like this with 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())
Try The following:
While dr.Read()
Dim monthly = dr("Monthly")
End While
MsgBox(monthly)
精彩评论