Hey everyone
I'm trying to update a form of mine ( You can see why from this post: http://www.vbforums.com/showthread.p...met&highlight=)
Here's my code so far, it executes without any exceptions but it doesn't update the data. Can anyone tell me why?
I'm trying to update a form of mine ( You can see why from this post: http://www.vbforums.com/showthread.p...met&highlight=)
Here's my code so far, it executes without any exceptions but it doesn't update the data. Can anyone tell me why?
Code:
Try
'=================================='
link_to_database()
Dim UpdateCommand As New SqlCommand
UpdateCommand.CommandText = "UPDATE MDModels SET MDModel_Name=@NewModelName, MDModel_CAT=@ModelCat, MDModel_Desc=@ModelDesc, " & _
"MDModel_Price=@ModelPrice WHERE MDUser_ID = @user AND MDModel_Name = @OldModelName"
UpdateCommand.Parameters.Add("@user", SqlDbType.Int)
UpdateCommand.Parameters.Add("@OldModelName", SqlDbType.NVarChar)
UpdateCommand.Parameters.Add("@NewModelName", SqlDbType.NVarChar)
UpdateCommand.Parameters.Add("@ModelCat", SqlDbType.NVarChar)
UpdateCommand.Parameters.Add("@ModelDesc", SqlDbType.NVarChar)
UpdateCommand.Parameters.Add("@ModelPrice", SqlDbType.Int)
UpdateCommand.Parameters("@NewModelName").Value = txtModelName_EditModel.Text
UpdateCommand.Parameters("@ModelCat").Value = ddbCategory_EditModel.Text
UpdateCommand.Parameters("@ModelDesc").Value = txtModelDesc_EditModel.Text
UpdateCommand.Parameters("@ModelPrice").Value = CType(Me.txtPrice_EditModel.Text, Integer)
UpdateCommand.Parameters("@user").Value = DatabaseModule.UserID
UpdateCommand.Parameters("@OldModelName").Value = ddbCurrentModel_EditModel.Text
UpdateCommand.Connection = DatabaseModule.con
'Opens connection to the database
DatabaseModule.con.Open()
'Transfer data to the database
UpdateCommand.ExecuteNonQuery()
DatabaseModule.con.Close()
'=================================='
Catch ex As Exception
Dim ExpectionOccured As DialogResult = MessageBox.Show(ex.Message & " Please contact an administrator", "An error has occured!", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try