I have an Access database and I want to fill some text boxes with data from a table. I'm using the following method for an example:

Me.txtCompany.Text = dr.GetString(1)

That works great. I have that in the PageLoad event.

Then I want a user to be able to change that value and submit it and have it update the database field.

So to do that, I have something like this:

strSQLCompany = "UPDATE Customers SET CompanyName='" & txtCompany.Text.Replace("'", "_") & "'"

This, however, doesn't work. It updates the database with the data that's entered into the text boxes on PageLoad instead of what's typed. I have the above code in my button click event.

I've tested my button click event by taking out the fill code in the PageLoad (making empty text boxes) and filling them in and submitting it and the correct information gets updated in the database, so I know that part of the code is correct.

Is there a reason why the button click event is taking the text from PageLoad instead of what's actually typed in the text box?

10 Years
Discussion Span
Last Post by mindfrost82

Have you written your code in IsPostBack method ?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
   Me.txtCompany.Text = dr.GetString(1)
End If

Protected Sub CmdSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmdSave.Click
Dim strSQLCompany  as String
strSQLCompany = "UPDATE Customers SET CompanyName='" & txtCompany.Text.Replace("'", "_") & "'"    
End Sub




I'm working on another site and I'm running into this same problem again (I never got it to work before either).

In the Page_Load event, I tried doing your If Not IsPostBack suggestion for filling the text boxes and I still get the same result.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.