【发布时间】:2013-04-11 08:20:08
【问题描述】:
我有这个代码是我自己研究的, 它不返回错误,它会更新在文本框中输入的一些数据,但不会更新所有字段
我检查正在更新的字段附近的代码,以将其与未更新的文本框进行比较 更新。
但我看不出有什么区别,它只是没有更新所有字段,只有一些字段
Dim sqlconn As New SqlClient.SqlConnection
sqlconn.ConnectionString = "server = SKPI-APPS1;" & _
"Database = EOEMS;integrated security=true"
Dim myCommand As SqlCommand
Try
'update command
sqlconn.Open()
myCommand = New SqlCommand(
"UPDATE tblOfficeEquipmentProfile SET OE_Category = '" & cmbCategory.Text
& "',OE_SubCategory = '" & cmbSubCategory.Text
& "', OE_Name = '" & txtName.Text
& "', OE_User = '" & txtUser.Text
& "', OE_Brand = '" & cmbBrand.Text
& "', OE_Model = '" & cmbModel.Text
& "', OE_Specs = '" & txtSpecs.Text
& "', OE_SerialNo = '" & txtSerialNo.Text
& "', OE_PropertyNo = '" & txtPropertyNo.Text
& "', OE_MacAddress = '" & txtMacAddress.Text
& "', OE_Static_IP = '" & txtStaticIp.Text
& "', OE_Vendor = '" & cmbVendor.Text
& "', OE_PurchaseDate = '" & txtPurchaseDate.Text
& "', OE_WarrantyInclusiveYear = '" & cmbWarrantyInclusiveYear.Text
& "', OE_WarrantyStatus = '" & txtWarrantyStatus.Text
& "', OE_Status = '" & txtStatus.Text
& "', OE_Dept_Code = '" & cmbDeptCode.Text
& "', OE_Location_Code = '" & cmbLocationCode.Text
& "', OE_Remarks ='" & cmbRemarks.Text
& "' WHERE OE_ID = '" & txtOEID.Text & "'", sqlconn)
' ^^ (edited to separate lines for ease of viewing )
myCommand.ExecuteNonQuery()
MessageBox.Show("Office Equipment Profile Successfully Updated Records")
Catch ex As Exception
MsgBox(ex.Message)
End Try
【问题讨论】:
-
我们没有您的数据库或数据,所以 us 无法运行您的代码 - 所以也许您可以给我们一些提示 - 例如你说“一些领域”——也许告诉我们哪些有效,哪些无效?
-
另外,您需要考虑使用参数化查询
-
哪些字段没有更新?
-
只更新的字段是OE_Name、OE_Specs、OE_SerialNo、OE_PropertyNo,其余没有更新我的主键是OE_ID
-
@ivandiglasan 你确实意识到编写这样的代码是对 SQL 注入攻击的邀请,对吧?
标签: sql vb.net winforms sqlcommand