我将一个变量(记录 ID)从具有数据网格的表单传递到不同的网络表单,以便我可以更新该特定记录。当我尝试更新记录时,我的问题就出现了。文本框的值更改为新数据,但程序在更改发生之前传递文本框的值。我的快速解决方案是向按钮添加回发,以检查这是否会有所作为。仅当我对记录 ID 字段进行硬编码时,这才能正常工作,回发会删除我传递给新表单的参数。
有谁知道如何解决这个问题?如您所见,我是 ASP.Net 的新手。
这是我的按钮的 ASP 代码:
asp:Button ID="btnSaveChanges" runat="server" Text="Save Changes" postbackurl="~/EditContact.aspx" Width="101px"
这是我必须更新记录的VB代码:
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 = '" & txtFirstName.Text & "', ContactMiddleName = '" & txtMiddleName.Text & "',ContactLastName = '" & txtLastName.Text & "', ContactAddress = '" & txtAddress.Text & "', ContactCity = '" & txtCity.Text & "', ContactState = '" & txtState.Text & "', ContactZipCode = '" & txtZipCode.Text & "', ContactPhone = '" & txtHomePhone.Text & "', ContactCell = '" & txtCell.Text & "', ContactEmail='" & txtEmail.Text & "' where ContactID = 6"
objCmd = New OleDbCommand(strSQL, objConnection)
objCmd.ExecuteNonQuery()
'Close Connection
objConnection.Close()
Response.Write("Record updated successfully")