本文介绍了在vb.net中使用sql参数更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码返回错误,指出
my code returns error saying
这是我的代码:
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim sqlconn As New SqlClient.SqlConnection
sqlconn.ConnectionString = "server = SKPI-APPS1;" & _
"Database = EOEMS;integrated security=true"
Dim myCommand As SqlCommand
'parametrized update sql command
Try
sqlconn.Open()
myCommand = New SqlCommand("UPDATE tblOfficeEquipmentProfile SET OE_Category = @OE_Category, OE_SubCategory = @OE_SubCategory, OE_ID = @OE_ID, OE_Name = @OE_Name, OE_User = @OE_User, OE_Brand = @OE_Brand, OE_Model =@OE_Model, OE_Specs =@OE_Specs, OE_SerialNo =@OE_SerialNo, OE_PropertyNo = @OE_PropertyNo, OE_MacAddress = @OE_MacAddress, OE_Static_IP = @OE_Static_IP, OE_Vendor = @OE_Vendor, OE_PurchaseDate =@OE_PurchaseDate, OE_WarrantyInclusiveYear=@OE_WarrantyInclusiveYear, OE_WarrantyStatus=@OE_WarrantyStatus,OE_Status=@OE_Status,OE_Dept_Code=@OE_Dept_Code,OE_Location_Code=@OE_Location_Code,OE_Remarks=@OE_Remarks", sqlconn)
myCommand.Parameters.Add("@OE_Category", cmbCategory.Text)
myCommand.Parameters.Add("@OE_SubCategory", cmbSubCategory.Text)
myCommand.Parameters.Add("@OE_ID", txtOEID.Text)
myCommand.Parameters.Add("@OE_Name", txtName.Text)
myCommand.Parameters.Add("@OE_User", txtUser.Text)
myCommand.Parameters.Add("@OE_Brand", cmbBrand.Text)
myCommand.Parameters.Add("@OE_Model", cmbModel.Text)
myCommand.Parameters.Add("@OE_Specs", txtSpecs.Text)
myCommand.Parameters.Add("@OE_SerialNo", txtSerialNo.Text)
myCommand.Parameters.Add("@OE_PropertyNo", txtPropertyNo.Text)
myCommand.Parameters.Add("@OE_MacAddress", txtMacAddress.Text)
myCommand.Parameters.Add("@OE_Static_IP", txtStaticIp.Text)
myCommand.Parameters.Add("@OE_Vendor", cmbVendor.Text)
myCommand.Parameters.Add("@OE_PurchaseDate", txtPurchaseDate.Text)
myCommand.Parameters.Add("@OE_WarrantyInclusiveYear", cmbWarrantyInclusiveYear.Text)
myCommand.Parameters.Add("@OE_WarrantyStatus", txtWarrantyStatus.Text)
myCommand.Parameters.Add("@OE_Status", txtStatus.Text)
myCommand.Parameters.Add("@OE_Dept_Code", cmbDeptCode.Text)
myCommand.Parameters.Add("@OE_Location_Code", cmbLocationCode.Text)
myCommand.Parameters.Add("@OE_Remarks", cmbRemarks.Text)
myCommand.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
MsgBox("Successfully Updated Records")
End Try
End Sub
推荐答案
p>检查表tblOfficeEquipmentProfile的主键
Check primary key of table tblOfficeEquipmentProfile
根据主要文件,您可以更新其余字段,即删除主键文件的更新
Based on primary filed you can update rest of the fields, means remove updation of primary key fileds
这篇关于在vb.net中使用sql参数更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!