I've got a form prepopulated from a row in a database (grabs the querystring from the URL to determine the row) and this works fine. I'm using the pageload function on the code-behind file to do this.

The button onclick has a function that is supposed to take the data from the form and put it back to the database. Here's that code:

using (SqlConnection updater = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ToString()))
                string up = "UPDATE roomtable SET ";
                up += "name='" + namein.Text.ToString() + "', country='" + countryin.Text.ToString() + "', state='" + statesin.Text.ToString() + "' ";
                up += "WHERE rid=" + curid;
                //curid is already declared and correct

                SqlCommand finalupdate = new SqlCommand(up);
                finalupdate.Connection = updater;

However, when I replace the form.Text.ToString() with hardcoded data, it will work after TWO clicks of the button. The first click will refresh the page (and the data on all of form elements) and the second click will apply the hardcoded changes to the database.

Any ideas on what I am doing wrong?
Thank you!!

8 Years
Discussion Span
Last Post by dnanetwork

you have to rebind all the values...

i.e update works on first click but you dont update the row values.

so after update query fire the select query and rebind your controls.

it should work

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.