Sign uporlog into customize your list.
Start here for a quick overview of the site
Detailed answers to any questions you might have
Discuss the workings and policies of this site
Learn more about Stack Overflow the company
Learn more about hiring developers or posting ads with us
Join Stack Overflowto learn, share knowledge, and build your career.
I currently have a problem attepting to update a record within my database. I have a webpage that displays in text boxes a users details, these details are taken from the session upon login. The aim is to update the details when the user overwrites the current text in the text boxes.
I have a function that runs when the user clicks the Save Details button and it appears to work, as i have tested for number of rows affected and it outputs 1. However, when checking the database, the record has not been updated and I am unsure as to why.
Ive have checked the SQL statement that is being processed by displaying it as a label and it looks as so:
The function and other relevant code is:
Sub Page_Load(sender As Object, e As EventArgs) usernameLabel.text = ntents.item(UserName) if usernameLabel.text = then logoutButton.Visible = False loggedInAsLabel.Visible = False else labelGuest.Visible = False linkLogin.Visible = False linkRegister.Visible = False end if emailBox.text = session.contents.item(Email) firstBox.text = session.contents.item(FirstName) lastBox.text = session.contents.item(LastName) promoBox.text = session.contents.item(Promo) End Sub Sub Button1_Click(sender As Object, e As EventArgs) changeDetails(emailBox.text, firstBox.text, lastBox.text, promoBox.text) End Sub Function changeDetails(ByVal email As String, ByVal firstname As String, ByVal lastname As String, ByVal promo As String) As Integer Dim connectionString As String = Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Documents an& _ d Settings\Paul Jarratt\My Documents\ticketoffice\datab\ticketoffice.mdb Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString) Dim queryString As String = UPDATE [users] SET [email]=@email, [firstname]=@firstname, [lastname]=@lastname, & _ [promo]=@promo WHERE ([users].[user_id] = + session.contents.item(ID) + ) Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand dbCommand.CommandText = queryString dbCommand.Connection = dbConnection Dim dbParam_email As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter dbParam_email.ParameterName = @email dbParam_email.Value = email dbParam_email.DbType = System.Data.DbType.[String] dbCommand.Parameters.Add(dbParam_email) Dim dbParam_firstname As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter dbParam_firstname.ParameterName = @firstname dbParam_firstname.Value = firstname dbParam_firstname.DbType = System.Data.DbType.[String] dbCommand.Parameters.Add(dbParam_firstname) Dim dbParam_lastname As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter dbParam_lastname.ParameterName = @lastname dbParam_lastname.Value = lastname dbParam_lastname.DbType = System.Data.DbType.[String] dbCommand.Parameters.Add(dbParam_lastname) Dim dbParam_promo As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter dbParam_promo.ParameterName = @promo dbParam_promo.Value = promo dbParam_promo.DbType = System.Data.DbType.[String] dbCommand.Parameters.Add(dbParam_promo) Dim rowsAffected As Integer = 0 dbConnection.Open Try rowsAffected = dbCommand.ExecuteNonQuery Finally dbConnection.Close End Try labelTest.text = rowsAffected.ToString() if rowsAffected = 1 then labelSuccess.text = * Your details have been updated and saved else labelError.text = * Your details could not be updated end if End Function
Any help would be greatly appreciated.
Have you checked to ensure that session.contents.item(ID) is what you expect it to be? If it is not equal to [users].[user_id] in any of the records, nothing will be updated.
Yes I have, I output the full SQL query to a string to test it and the statement is correct. Also the rowsAffected variable is set to 1 after the function.
I am wondering if it has anything to do with the fact that the textboxes already have the user details in them, when the page is loaded and then it requires the user to overwrite the textbox text? Could this be a problem area?
I have just added the code for the Page_Load procedure to the question. I think it may have something to do with the fact I am using filling the textboxes with the session values in this procedure and it is therefore using those values in the UPDATE statement. How can I get around this problem?
Can you trace the code? See if the textbox-setting code is run after the user has updated the page but before the SQL is set up and run. Also, consider refactoring all the parameter creation code into a function at which point it will be easy to add a debug switch to inspect the value of every parameter that is set.
Does your page have a RequiresTransaction property? If so, check that there are no exceptions thrown elsewhere during the request which might cause the transaction to roll back – leaving the data unchanged.
There is no RequiresTransaction in my page. However I have just done a test. Currently the page would fill the textboxes with the session values for the user and the user would have to overwrite and submit. I have stopped the textboxes from using the session data and left them blank and then filled in the textboxes and the database updates correctly. So it appears the problem is that it is updating using the original textbox values when the query is run even if I overwrite them? Therefore it is just updating the table with the previous data resulting in no change?
Are you sure that youre updating the database you think youre updating? I dont like the look of that connection string at all (and, frankly, I doubt Paul Jarratt would be too happy to see it posted here).
Get theweekly newsletter!In it, youll get:
Why blow Franks cover in Oceans Eleven (2001)?
No iBook app on iPhone X; cannot find app in App Store
What are the region-space combinations that can be used for button and panel registration
ATMEGA328 decoupling caps: are they in right position?
How do they ensure there is one electron on an oil drop in Millikans oil drop experiment?
Why cant a causal digital filter have an infinitely sharp transition between the passband and the stopband?
Why dont chilli peppers taste as hot in space?
In end-to-end encryption, doesnt the server need to be trusted?
Items derived from one function are getting printed within another for loop in another function
How did Rusty know that Bashers bank heist would fail?
What binary relation is neither symmetric, nor asymmetric nor antisymmetric?
Why the equation number is not coming in the same column in a double column document?
What is the difference between Shrimad Bhagavatam and Bhagavad Gita?
Meaning of metrics in Google cloud console
Can I legally drive in France with an Indian driving licence?
How to deal with a complete failure in a group research?
How does Santa fit down the chimney?
How can I politely explain to a DM that removing player agency is usually bad?
Making calculation of correlation dimension faster
Is my account balance publicly visible?
site design / logo 2017 Stack Exchange Inc; user contributions licensed undercc by-sa 3.0withattribution required.rev 2017.12.22.28257