![](/img/trans.png)
[英]multiple datagridview data update to database mysql - vb.net
[英]How to sum datagridview contents to database VB.net multiple users
如何匯總數據庫中datagridview的內容。 我有顯示的代碼,但是它只是更新而不是總和。
所以這是我保存的代碼:
Public Sub save_dgv()
Try
con.Close()
con.Open()
Dim scb = New MySqlCommandBuilder(SDA)
SDA.Update(dbDataset)
MessageBox.Show("Submitted!")
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
sample:
user1
id--row1--row2--total
1 --25 -- 23 --48
user2
id--row1--row2--total
1 --25 -- 23 --48
output
id--row1--row2--total
1 --50-- 46--96
請嘗試以下方法。 調整數據類型為您的數據庫。 在SQL Server中有效,但未在MySQL中進行測試。
Using cn As New MySqlConnection("Your connection string")
Dim s As String = "Update MyTable Set row1 = row1 + @row1, row2 = row2 + @row2 where id = @id"
Using cmd As New MySqlCommand(s, cn)
cmd.Parameters.Add("@row1", MySqlDbType.Int32).Value = intRow1
cmd.Parameters.Add("@row2", MySqlDbType.Int32).Value = intRow2
cmd.Parameters.Add("@id", MySqlDbType.Int32).Value = intID
cn.Open()
cmd.ExecuteNonQuery()
End Using
End Using
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.