批量更新 mysql 表并从 datagridview 计算值。VB.NET
发布时间:2022-06-17 17:47:56 207
相关标签: # 数据库
我想使用datagridview中的值批量更新我的数据库表,但我还需要先求datagridview和mysql表的值之和。我该怎么做?
这是我的更新按钮的当前代码
For Each row As DataGridViewRow In dgvStok.Rows
If (Not row.IsNewRow) Then
Dim ID As DataGridViewCell = row.Cells("ID").Value
Dim Stok As DataGridViewCell = row.Cells("Stok").Value
conn = New MySqlConnection('myconnstring)
conn.Open()
cmd = New MySqlCommand("Select * from tbStok where ID='" & ID & "'", conn)
dr = cmd.ExecuteReader
dr.Read()
If dr.HasRows Then
Dim StokInventory, IncomingStok As Integer
StokInventory = dr.Item("Stok")
TotalStok = StokInventory + IncomingStok
Dim updateStok As String = "update tbStok set Stok ='" & TotalStok & "' where ID = '" & ID & "'"
cmd = New MySqlCommand(updateStok, conn)
cmd.ExecuteNonQuery()
End If
conn.Close()
End If
Next
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报