Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating SQL records from textboxes using ASP.Net 2010
    text
    copied!<p>I am passing a variable (record ID) from a form that has a data grid to a different webform so that I can update that specific record. My issue comes when I try to update the record. The value of the textboxes change to the new data but the program is passing the values of the textboxes before changes take place. My quick solution was to add postback to the button just to check if this would make a difference. This worked fine only if I hard coded the record ID field, postback erases the parameter I am passing to the new form.</p> <p>Does anyone have an idea how to address this? As you can see, I am new to ASP.Net.</p> <p>This is my ASP code for the button: </p> <p><code>asp:Button ID="btnSaveChanges" runat="server" Text="Save Changes" postbackurl="~/EditContact.aspx" Width="101px"</code></p> <p>And here is the VB Code I have to update the record:</p> <pre><code> Dim tempContactID As String = Request.QueryString().ToString Dim objConnection As OleDbConnection = Nothing Dim objCmd As OleDbCommand = Nothing Dim strConnection As String, strSQL As String 'Connection String to Database strConnection = "provider=SQLOLEDB;data source=HP-G640;Database=Contacts;user ID=contactsUser;password=password;" objConnection = New OleDbConnection(strConnection) objConnection.ConnectionString = strConnection objConnection.Open() strSQL = "update ContactDetails set ContactFirstName = '" &amp; txtFirstName.Text &amp; "', ContactMiddleName = '" &amp; txtMiddleName.Text &amp; "',ContactLastName = '" &amp; txtLastName.Text &amp; "', ContactAddress = '" &amp; txtAddress.Text &amp; "', ContactCity = '" &amp; txtCity.Text &amp; "', ContactState = '" &amp; txtState.Text &amp; "', ContactZipCode = '" &amp; txtZipCode.Text &amp; "', ContactPhone = '" &amp; txtHomePhone.Text &amp; "', ContactCell = '" &amp; txtCell.Text &amp; "', ContactEmail='" &amp; txtEmail.Text &amp; "' where ContactID = 6" objCmd = New OleDbCommand(strSQL, objConnection) objCmd.ExecuteNonQuery() 'Close Connection objConnection.Close() Response.Write("Record updated successfully") </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload