VB.NET从mySQL数据库计算DataTable中列的值总和

时间:2017-02-14 08:08:59

标签: mysql vb.net datatable

我有点困惑。我有一个mySQL数据库。它是散列/加密的。我使用了MySqlDataReader,我的第一个查询是:

SELECT SUM(column01) FROM dbtest.table01 WHERE column02 = '" & encrypt(selectedValue, salt) & "'

问题是,数据库内的数据是经过散列/加密的,这就是无法计算数据的原因。现在我使用此查询切换到MySqlDataAdapter,我在DataGridView中显示数据(此处显示了deshahed / decrypted数据):

SELECT column01 FROM dbtest.table01 WHERE column02 = '" & encrypt(_selectedValue, salt) & "'

到目前为止,这是我的代码。

Dim dataAdapter As New MySqlDataAdapter
Dim dataTable As New DataTable
Dim bSource As New BindingSource

Try
   conn.Open()
   Dim query As String
   query = "SELECT column01 FROM dbtest.table01 WHERE column02 = '" & encrypt(_selectedValue, salt) & "'"
   command = New MySqlCommand(query, conn)
   dataAdapter.SelectCommand = command
   dataAdapter.Fill(dataTable)
   bSource.DataSource = dataTable
   DataGridView_Moon.DataSource = bSource

   For i As Integer = 0 To dataTable.Rows.Count - 1
       dataTable.Rows(i)("column01") = decrypt(dataTable.Rows(i)("column01"), salt)
   Next

   conn.Close()
Catch ex As Exception
Finally
   conn.Dispose()
End Try

如果可以,请将totalValue放入消息框中。感谢

0 个答案:

没有答案