繁体   English   中英

如何更新vb.net 2013 SQL Server 2008中的特定列

[英]How to update specific column in vb.net 2013 SQL Server 2008

我有4个表格: Code_Product, Name_Product, Color_Product, Size_Product

和代码:

 Public Sub ExecuteQuery(query As String)
       Dim command As New SqlCommand(query, connection)
      command.ExecuteNonQuery()
End Sub

Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click

Dim updateQuery As String = "UPDATE tbl_Product SET Name_Product = '" & txtNameProduct.Text & "' , Color_Product = '" & txtColorProduct.Text & "', Size_Product = '" & txtSizeProduct.Text & "' where Kode_Produk= '" & txtKodeProduk.Text & "'"

ExecuteQuery(updateQuery)

MessageBox.Show("Data has been changed")

注意:代码工作正常。

但是,代码更改了所有列,而我只想只更改一列。 怎么样?

替换这条线

Dim updateQuery As String = "UPDATE tbl_Product SET Name_Product = '" & txtNameProduct.Text & "' , Color_Product = '" & txtColorProduct.Text & "', Size_Product = '" & txtSizeProduct.Text & "' where Kode_Produk= '" & txtKodeProduk.Text & "'"

有了这个。 仅传递您要更新的列。

Dim updateQuery As String = "UPDATE tbl_Product SET Name_Product = '" & txtNameProduct.Text & "'  where Kode_Produk= '" & txtKodeProduk.Text & "'"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM