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()))
            {
                updater.Open();
                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;
                finalupdate.ExecuteNonQuery();
                updater.Close();                
            }

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!!

whoops, this is supposed to go to the asp.net forum but i don't know how to move it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.