|
|
Question : how do i update primary key
|
|
Experts,
I have been on this for days. The primary key in my database is used as a product id, so it is not set to autoincrement.
I CAN UPDATE other fields but not the prodid, how do i correct this
thanks
========================sp========================= ALTER PROCEDURE SPR_UPDATE_PRODUCTS ( @prodID int, @prodCode varchar(10), @prodName varchar(30), @prodDesc varchar(200), @pfID int, @prodLicName varchar(50), @prodLicEncKey varchar(20), @supported smallint, @licVersion smallint, @prodAltCode varchar(10) ) AS UPDATE product SET prodID =@prodID, prodCode =@prodCode, prodName =@prodName, prodDesc =@prodDesc, pfID =@pfID, prodLicName =@prodLicName, prodLicEncKey =@prodLicEncKey, supported =@supported, licVersion =@licVersion, prodAltCode =@prodAltCode WHERE prodID = @prodID GO
==============================calling code================================== 'Updates users Public Shared Function UpdateProduct(ByVal productProfile As ProductProfile) As Boolean Dim DBConnection As SqlConnection = Connection() Dim ProdID As SqlParameter DBConnection.Open() Try Dim cmdproduct As SqlCommand = New SqlCommand("SPR_UPDATE_PRODUCTS", DBConnection) cmdproduct.CommandType = CommandType.StoredProcedure cmdproduct.Parameters.Add("@prodID", productProfile.prodID) cmdproduct.Parameters.Add("@prodCode", productProfile.prodCode) cmdproduct.Parameters.Add("@prodName", productProfile.prodName) cmdproduct.Parameters.Add("@prodDesc", productProfile.prodDesc) cmdproduct.Parameters.Add("@pfID", productProfile.pfID) cmdproduct.Parameters.Add("@prodLicName", productProfile.prodLicName) cmdproduct.Parameters.Add("@prodLicEncKey", productProfile.prodLicEncKey) cmdproduct.Parameters.Add("@supported", productProfile.supported) cmdproduct.Parameters.Add("@licVersion", productProfile.licVersion) cmdproduct.Parameters.Add("@prodAltCode", productProfile.prodAltCode) Dim iCount As Integer iCount = cmdproduct.ExecuteNonQuery() If iCount > 0 Then Return True Else Return False End If Catch ex As Exception System.Diagnostics.Debug.WriteLine(ex.ToString) Finally DBConnection.Close() End Try End Function
|
Answer : how do i update primary key
|
|
why you are trying to updated that column which is used for filter the record and you are also updating with the same value.
Please look below modified code...
ALTER PROCEDURE SPR_UPDATE_PRODUCTS ( @prodID int, @prodCode varchar(10), @prodName varchar(30), @prodDesc varchar(200), @pfID int, @prodLicName varchar(50), @prodLicEncKey varchar(20), @supported smallint, @licVersion smallint, @prodAltCode varchar(10) ) AS UPDATE product SET prodCode =@prodCode, prodName =@prodName, prodDesc =@prodDesc, pfID =@pfID, prodLicName =@prodLicName, prodLicEncKey =@prodLicEncKey, supported =@supported, licVersion =@licVersion, prodAltCode =@prodAltCode WHERE prodID = @prodID GO
|
|
|
|
|