2011-08-29 95 views
0

好吧,我3天前得知這個查詢: -獲取從列的求和值的總價值,MySQL的

SELECT SUM(DTotal) AS Monthly FROM bdailytotal 

,但我要如何查看總和的總價值?我一直在尋找這個,但是我得到的大部分答案都是針對PHP的。有人可以告訴我如何將總價值分配給VB.NET中的變量嗎?

或教我如何將該總值分配給另一個表。

+0

你是什麼看法呢?這些都在查詢中。 –

+0

是啊我知道,總數是在每月,但我怎麼稱呼它? –

+0

total = reader [「monthly」] –

回答

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()) 
+0

它的工作原理。是。謝謝 –

0

嘗試以下操作:

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

MsgBox(monthly) 
+0

它不起作用 –